Jump to content

Restarting integration triggers automations


Recommended Posts

Posted

I have a couple of automations I'm using to bridge between ISY and HA which unintentionally trigger when the Universal Devices ISY/IoX integration starts even though the state hasn't actually changed (examples below).

This happens when I restart HA (even quick reload) and when  I reload the ISY/IoX integration.

This is a trigger for a variable of the water heater temp I'm passing to HA:

platform: state
entity_id:
  - sensor.i_ha_watertempset

This is a trigger for sensor I've create in ISY for a virtual switch status:

platform: state
entity_id:
  - sensor.garage_door_12
for:
  hours: 0
  minutes: 0
  seconds: 3

In the first example, the automation just causes the temp to be reset to it current value which is no big deal but the other triggers the MyQ garage door to open which is obviously not acceptable.

Appreciate any help as I'm quite a novice on HA automations. Thanks!

 

Posted
10 minutes ago, DaveStLou said:

I have a couple of automations I'm using to bridge between ISY and HA which unintentionally trigger when the Universal Devices ISY/IoX integration starts even though the state hasn't actually changed (examples below).

This happens when I restart HA (even quick reload) and when  I reload the ISY/IoX integration.

This is a trigger for a variable of the water heater temp I'm passing to HA:

platform: state
entity_id:
  - sensor.i_ha_watertempset

This is a trigger for sensor I've create in ISY for a virtual switch status:

platform: state
entity_id:
  - sensor.garage_door_12
for:
  hours: 0
  minutes: 0
  seconds: 3

In the first example, the automation just causes the temp to be reset to it current value which is no big deal but the other triggers the MyQ garage door to open which is obviously not acceptable.

Appreciate any help as I'm quite a novice on HA automations. Thanks!

 

I am as much a novice on HA automations as you, or maybe even more novice, but can you post the full automation as the above does not appear to be (to me at least) the full automation ?

Posted (edited)
1 hour ago, asbril said:

I am as much a novice on HA automations as you, or maybe even more novice, but can you post the full automation as the above does not appear to be (to me at least) the full automation ?

This is the garage door automation:

alias: Operate Garage Door - ISY trigger
description: |-
  Added 3 second delay before if then evaluated. ISY communication delay?
  Trigger MyQ to operate door based on Garage Door Switch (virtual 12)
trigger:
  - platform: state
    entity_id:
      - sensor.garage_door_12
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition: []
action:
  - if:
      - condition: state
        entity_id: switch.garage_door_v12
        state: "off"
    then:
      - device_id: 23ed29295bc9bfe28813b72f2b489127
        domain: cover
        entity_id: cover.garage_door
        type: close
    else:
      - device_id: 23ed29295bc9bfe28813b72f2b489127
        domain: cover
        entity_id: cover.garage_door
        type: open
mode: single

And the water heater automation:

alias: Set Water Temperature-ISY trigger
description: "Set Rheem Water Heater temperature when i.HA.WaterTemp (56) "
trigger:
  - platform: state
    entity_id:
      - sensor.i_ha_watertempset
condition:
  - condition: numeric_state
    entity_id: sensor.i_ha_watertempset
    above: 99
    below: 131
action:
  - service: water_heater.set_temperature
    data:
      temperature: "{{ states('sensor.i_ha_watertempset')| int }}"
    target:
      entity_id: water_heater.rheem_water_heater
  - service: notify.alexa_media_office_dot
    data:
      message: Water heater set to {{ states('sensor.i_ha_watertempset')| int }}
  - service: notify.mobile_app_dave_mobileapp
    data:
      message: Water heater set to {{ states('sensor.i_ha_watertempset')| int }}
mode: single

 

Edited by DaveStLou
Replaced with production automation rather than test copied in error
Posted
3 minutes ago, DaveStLou said:

This is the garage door automation:

alias: Operate Garage Door - ISY trigger
description: |-
  Needs 3 second delay before if then evaluated. ISY communication delay?
  Trigger MyQ to operate door based on Garage Door Switch (virtual 12)
trigger:
  - platform: state
    entity_id:
      - sensor.garage_door_12
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.garage_door_12
        state: unknown
action:
  - if:
      - condition: state
        entity_id: switch.garage_door_v12
        state: "off"
    then:
      - device_id: 23ed29295bc9bfe28813b72f2b489127
        domain: cover
        entity_id: cover.garage_door
        type: close
    else:
      - device_id: 23ed29295bc9bfe28813b72f2b489127
        domain: cover
        entity_id: cover.garage_door
        type: open
mode: single

And the water heater automation:

alias: Set Water Temperature-ISY trigger
description: "Set Rheem Water Heater temperature when i.HA.WaterTemp (56) "
trigger:
  - platform: state
    entity_id:
      - sensor.i_ha_watertempset
condition:
  - condition: numeric_state
    entity_id: sensor.i_ha_watertempset
    above: 99
    below: 131
action:
  - service: water_heater.set_temperature
    data:
      temperature: "{{ states('sensor.i_ha_watertempset')| int }}"
    target:
      entity_id: water_heater.rheem_water_heater
  - service: notify.alexa_media_office_dot
    data:
      message: Water heater set to {{ states('sensor.i_ha_watertempset')| int }}
  - service: notify.mobile_app_dave_mobileapp
    data:
      message: Water heater set to {{ states('sensor.i_ha_watertempset')| int }}
mode: single

 

Thanks,  hopefully more knowledgeable HA users will chime in. I don't see anything immediately, but I have always asked myself what occurs when in an Automation there is both a Trigger and a IF.

Posted

@DaveStLou In the Water Heater temp automation, I assume this is coming from the ISY int variable being set from unknown to whatever value the ISY has.  to avoid that, you can perhaps add a "condition" to compare the temp the water heater is already set to, to the value of that variable and only continue when the values are different. 

On MyQ, I don't actually use these 2 automatons anymore, because the ISY no longer needs to be able to control the barn overhead door, but I didn't remove it in case I ever wanted to use it again.  Today I'd probably use Choose in the action to combine these into 1, but I don't think Choose existed yet when they were created, these are actually among the very first automatons I created. (although they were recently updated to use the newer number.set_value instead of Call Service update variable)

The integer variable is normally 0, when the ISY wants to open the door the variable gets set to 1, when it wants to close the door the variable gets set to -1.  After HA changes the state, HA changes the ISY variable back to 0

alias: Barn OHD Close
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.idoor_barnohdbutton_actionrequest_ha
    below: "0"
condition: []
action:
  - service: cover.close_cover
    target:
      entity_id: cover.barn_2
    data: {}
  - service: number.set_value
    data:
      value: "0"
    target:
      entity_id: number.idoor_barnohdbutton_actionrequest_ha
mode: single

--------------------

alias: Barn OHD Open
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.idoor_barnohdbutton_actionrequest_ha
    above: "0"
condition: []
action:
  - service: cover.open_cover
    target:
      entity_id: cover.barn_2
    data: {}
  - service: number.set_value
    data:
      value: "0"
    target:
      entity_id: number.idoor_barnohdbutton_actionrequest_ha
mode: single

 

 

Posted
5 hours ago, MrBill said:

@DaveStLou In the Water Heater temp automation, I assume this is coming from the ISY int variable being set from unknown to whatever value the ISY has.  to avoid that, you can perhaps add a "condition" to compare the temp the water heater is already set to, to the value of that variable and only continue when the values are different.

That's what I figured is happening. Now I just have to figure out how to check that from the water heater entity

image.thumb.png.c51d9d825fd5c8ae58616a1a1bffe2a1.png

I tried updating the condition to this but it didn't work:

condition: and
conditions:
  - condition: template
    value_template: >-
      {{ ( states('sensor.i_ha_watertempset')) !=
      (state_attr('water_heater.rheem_water_heater', 'temperature'))}}
  - condition: numeric_state
    entity_id: sensor.i_ha_watertempset
    above: 99
    below: 131

 

On the other on the garage door, I used to have them as two separate automations but thought I should be able to combine them. The idea of only triggering if on or off was the last state gave me the idea to make this change to the trigger:

trigger:
  - platform: state
    entity_id:
      - sensor.garage_door_12
    for:
      hours: 0
      minutes: 0
      seconds: 3
    from: "Off"
    to: "On"
  - platform: state
    entity_id:
      - sensor.garage_door_12
    for:
      hours: 0
      minutes: 0
      seconds: 3
    from: "On"
    to: "Off"

which worked!

Posted (edited)
condition:
  - condition: template
    value_template: >
              {{ trigger.from_state.state != 'unavailable' }}
  - condition: template
    value_template: >
              {{ trigger.from_state.state != 'unknown' }}

 

Edited by shbatm
  • Thanks 1
Posted
2 hours ago, shbatm said:

condition:
  - condition: template
    value_template: >
              {{ trigger.from_state.state != 'unavailable' }}
  - condition: template
    value_template: >
              {{ trigger.from_state.state != 'unknown' }}

That did it. Thank you!

  • Like 1
Posted
2 hours ago, DaveStLou said:

That did it. Thank you!

I see @shbatm gave you a hint which lead to a solution for you, However I'll add a technique for finding your solution in the future without just guessing blindly.   Use the real-time template editor!  Developer Tools > Template which allows you to type templates and see the results in real time.   Here's a slide I made for someone else awhile back:

image.thumb.png.697436da2b560b7fd65de25464c8f785.png

For each line typed in the Template Editor (left side of the screen) there is a corresponding real-time result shown in the right column (I drew red lines to illustrate). 

As real-time conditions change the right column updates. For example, Line 17 of the editor utilizes an ISY State Variable "sAway.ha).  If I change the value of that variable in the ISY, the result here in the right column will immediately reflect that change.  In this case if sAway.ha = 2 then the "False" will change to "True", for any value other than 2 this expression is false.

As you can see the Template editor is a valuable tool (multi-line templates work also, these just all happan to be single line).  Once you've got the template working, you can just paste it where ever it needs to go.

  • Thanks 1
Posted
28 minutes ago, MrBill said:

As you can see the Template editor is a valuable tool (multi-line templates work also, these just all happan to be single line).  Once you've got the template working, you can just paste it where ever it needs to go.

Another handy one is dumping the trigger to the log to see the exact structure:

action:
  service: system_log.write
  data:
    message: "{{ trigger | to_json }}"
    level: debug

 

  • Thanks 1
  • 2 weeks later...
Posted

When doing a 'state' trigger - it will 'trigger' every time the integration restarts as you are seeing. This is because the value refreshes on reload - triggering even if the value didn't change. If you only want it to trigger when the value changes - you need a 'from' and/or a 'to'.

Here is what I have triggering on a sensor exposed from ISY:

platform: state
entity_id:
  - sensor.elkm1_door_to_garage
from: "off"
to: "on"

With this - there is no trigger when the integration restarts. Only when the sensor changes state in the defined direction (off to on in this case).   If you want both directions - simply add two triggering conditions in the automation with the 'from' and 'to' reversed between them. 'off' and 'on' may be different depending on how the sensor is configured in HA.

  • Like 1
Guest
This topic is now closed to further replies.

×
×
  • Create New...