Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95419

Elapsed timer automation

$
0
0

@ner0tic wrote:

I’m trying to implement an elapsed timer of sorts. I searched the forums and the internerd and tried using what I found.
It it works manually, but my automation says it works, but doesn’t. Basically, I want to keep track of how long my inverter is receiving an input from an AC feed.

# sensors
sensor:
  # AC Input Amps
  - platform: mqtt
    name: magnum_inverter_AACin
    state_topic: "powerpi/inverter"
    value_template: "{{ value_json.data.AACin }}"
    json_attributes_topic: "powerpi/inverter"
    json_attributes_template: "{{ value_json.data.AACin | tojson }}" 
    unit_of_measurement: A

  - platform: template
    sensors:
      # Elapsed Time [HACK]
      magnum_inverter_ac_input_on_time:
        value_template: >-
          {{ (as_timestamp(now()) - state_attr('input_datetime.magnum_inverter_ac_input', 'timestamp'))| timestamp_custom('%H:%M:%S', false) }}

# input boolean
input_boolean:
  # Aux AC Input
  magnum_inverter_ac_input:
    name: Aux AC Input
    initial: false

# input datetime
input_datetime:
  # AC Input Elapsed Timer
  magnum_inverter_ac_input:
    has_date: true
    has_time: true

# automation
## AC Input ##################################################
  ## ON
  - alias: Start AC Input Boolean
    trigger:
      - platform: numeric_state
        entity_id: sensor.magnum_inverter_aacin
        above: 0
    action:
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.magnum_inverter_ac_input
  ## OFF
  - alias: Deavtivate AC Input Boolean
    trigger:
      - platform: numeric_state
        entity_id: sensor.magnum_inverter_aacin
        below: 0.1
    action:
      service: input_boolean.turn_off
      data:
        entity_id: input_boolean.magnum_inverter_ac_input
  ## Start Elapsed Timer
  - alias: Start AC Input Elapsed Timer
    trigger:
      platform: state
      entity_id: input_boolean.magnum_inverter_ac_input
      to: 'on'
    action:
      service: input_datetime.set_datetime
      data:
        entity_id: input_datetime.magnum_inverter_ac_input
        datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
  ## Update Elapsed Timer
  - alias: Update Magnum Elapsed Timer
    trigger:
      platform: time_pattern
      seconds: '*'
    condition:
      condition: state
      entity_id: input_boolean.magnum_inverter_ac_input
      state: 'on'
    action:
      service: homeassistant.update_entity
      entity_id:  sensor.magnum_inverter_ac_input_on_time

it all acts like it works, but even when I run it manually the input_datetime doesn’t seem to actually get updated so my elapsed timer increments from whenever I manually set the state

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95419

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>