Not all actions triggering in automation

Im having a problem where I have two automations that are triggering however only the notify action is working when they are automatically triggered by the sensor the fan switch doesnt toggle. If I manually trigger the automations or manually change the state of the sensor both actions work fine.

The config:

- id: '1554661122087'
  alias: Cool Media Closet
  trigger:
  - above: '89.9'
    entity_id: sensor.vision_security_zp3111_multisensor_4in1_temperature
    platform: numeric_state
  condition:
  - condition: state
    entity_id: switch.media_closet_fan_switch
    state: 'off'
  action:
  - data:
      entity_id: switch.media_closet_fan_switch
    service: switch.turn_on
  - data:
      message: Media closet too warm, turning fan on
      title: Media Closet Fan
    service: notify.ios_my_iphone
- id: '1554661346041'
  alias: Cool Media Closet Off
  trigger:
  - below: '85.1'
    entity_id: sensor.vision_security_zp3111_multisensor_4in1_temperature
    platform: numeric_state
  condition:
  - condition: state
    entity_id: switch.media_closet_fan_switch
    state: 'on'
  action:
  - data:
      entity_id: switch.media_closet_fan_switch
    service: switch.turn_off
  - data:
      message: Media closet cool, turning fan off
      title: Media Closet Fan
    service: notify.ios_my_iphone

Both automations are enabled:
image

And I can see in the log book that the automation is trigger and im getting the notifications on my phone

Home Assistant 0.96.5 in docker

Suggestions?

While it doesn’t make any sense to see the results you are seeing in your automations, the only thing I notice that looks strange at all is that you are using a string instead of a number for the numeric_state in your trigger. Normally you would write those without any quotes around them. However, I would think that it would cause the automation to not trigger at all instead of just performing part of the actions.

but just as a test you could try to remove the quotes to see what happens. Other than that everything looks OK to me.

- id: '1554661122087'
  alias: Cool Media Closet
  trigger:
  - above: 89.9
    entity_id: sensor.vision_security_zp3111_multisensor_4in1_temperature
    platform: numeric_state
  condition:
  - condition: state
    entity_id: switch.media_closet_fan_switch
    state: 'off'
  action:
  - data:
      entity_id: switch.media_closet_fan_switch
    service: switch.turn_on
  - data:
      message: Media closet too warm, turning fan on
      title: Media Closet Fan
    service: notify.ios_my_iphone

Those were created from the UI, so thats probably why they ended up that way. I just updated the config and restarted, I’ll report back here as it updates.

No change.

I’ve got nothing…

If one action is taken then the other action has to be taken unless it’s something that is preventing it external to the automation.

Check the log for errors after the automaton runs automatically.

I was going to say check the switch entity id but you say it works if the automation is manually triggered.

This makes no sense to me.

I fully agree with that

Try this:

- id: '1554661122087'
  alias: Cool Media Closet
  trigger:
    platform: template
    value_template: >
      {{ states('sensor.vision_security_zp3111_multisensor_4in1_temperature') | float > 89.9 and
         is_state('switch.media_closet_fan_switch', 'off') }} 
  action:
  - service: notify.ios_my_iphone
    data:
      title: Media Closet Fan
      message: Media closet too warm, turning fan on
  - service: switch.turn_on
    entity_id: switch.media_closet_fan_switch

- id: '1554661346041'
  alias: Cool Media Closet Off
  trigger:
    platform: template
    value_template: >
      {{ states('sensor.vision_security_zp3111_multisensor_4in1_temperature') | float < 85.1 and
         is_state('switch.media_closet_fan_switch', 'on') }} 
  action:
  - service: notify.ios_my_iphone
    data:
      title: Media Closet Fan
      message: Media closet cool, turning fan off
  - service: switch.turn_off
    entity_id: switch.media_closet_fan_switch

Based on your description of when all the actions work, I have a hunch what the cause of the bad behavior might be … but it’s a long shot.

What does the JSON look like on the state page for switch.media_closet_fan_switch?

I reversed the order of the actions this morning now notify then switch and it seems to be working. I haven’t had a chance to look at the code yet, but i suspect this is a bug.

That’s one of two things done in the example I posted above.

I provided the example as part of an experiment to identify the cause of this issue. It not only reverses the order of the actions but integrates the original condition into the trigger. The goal here was for you to try the example as-is first. If it worked, the next step would be to put the actions back into the order you had (controlling the switch first, then issuing the notification). If that arrangement:

  • Failed, then it suggests there’s a quirk with the order of executed actions.
  • Succeeded, then it suggests the original condition caused the issue. Specifically, some sort of strange timing problem with a condition checking if a switch is in one state followed by an action that changes it to its opposite state (that’s the ‘long-shot’ I mentioned earlier).

If you’re not interested in trying the experiment then, based on your recent findings, it’s still inconclusive as to what is causing the problem. Moving the switch activation into the second position, effectively puts ‘distance’ (in terms of milliseconds of time) between the evaluation of the condition and activating the switch. This extra time may not be necessary if the condition is integrated into the trigger.

Knowing more about how this problem is caused is helpful when attempting to describe it as a GitHub Issue.

@123 - Happy to do the experiment for you. I just deployed it, I’ll let you know if it works.

1 Like

@123 your solution works as well. It also had the effect that constantly updates the switch rather than just triggering once (which is good & bad). Specifically if I want to turn the switch on at a lower temp, this doesnt allow that. But I could just disable the automation when I do that, so NBD.

Yes, the template will be evaluated whenever the temperature sensor changes state. However, don’t forget that the numeric_state trigger is effectively doing the same thing ‘under the hood’. Whenever the temperature changes it compares it to the above threshold.

Apologies but I don’t understand what you mean.

Say the temp is 80 and I manually turn the switch on, this automation will instantly turn the switch back off b/c it triggers on the state of the switch + the state of the sensor. The original one only triggered when the state crossed the temperature threshold.

1 Like

Thanks for the clarification. Yes, you’re absolutely right. The Template Trigger is now monitoring the switch as well. So if you manually turn the switch on or off, the Template Trigger will detect the change and evaluate the template (and potentially undo your action).

Like you said, that can be good or bad, it depends on the requirements.

  • Good if you don’t want to allow the switch to be turned off when the temperature is above the threshold. It will detect the switch was turned off and, because the temperature is still high, will turn it back on. Your original version can’t do this because it only monitors the temperature.

  • Bad because now you lose the ability to manually control the switch when the temperature is below the threshold. Your original version allows you to manually control the fan at all times.


Have you tried the second part of the experiment? Change the order of the actions in my automation so that the notification is last in the sequence.

If it fails then it means this issue is all about the order of the actions.

@123 Just tried reversing the actions, still worked. I’ve been triggering it by the switch and I want to make sure we test this with the temperature change as well. It’ll be a couple hours before the room is warm enough to trigger the fan. But I’ll update here when it does.

Thanks for performing all the tests. Interesting results! It appears the order of the actions is important when the automation uses a condition. Without a condition, the order is not critical.

The condition checks if the switch is off, then the first action in the sequence turns the switch on. This arrangement results in a problem (it fails to turn the switch on). Moving the action to be second in the sequence, cures the problem.

Without question it should not behave this way; the sequence order shouldn’t matter.

I tried to duplicate your results using an input_number and an input_boolean. The automation monitors this input_number:

input_number:
  range:
    name: Range
    initial: 25
    max: 50
    min: 1
    step: 1

and checks the state of this input_boolean:

input_boolean:
  toggler:
    name: toggler

then turns on the input_boolean and sends a notification:

  alias: 'sequence order'
  trigger:
  - platform: numeric_state
    entity_id: input_number.range
    above: 30
  condition:
  - condition: state
    entity_id: input_boolean.toggler
    state: 'off'
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.toggler
  - service: persistent_notification.create
    data_template:
      message: 'Value: {{ trigger.to_state.state }}'
      title: 'Automation Sequence Order triggered'

However, the order of the actions was not critical and the first action was always executed. So this simple experiment failed to duplicate your results.

Maybe the platform your switch is using influences the automation’s behavior? :thinking: :man_shrugging:

More data, so I just hit the point where it should have turned on and it did not with this ordering (I only got the notification):

- id: '1554661122087'
  alias: Cool Media Closet
  trigger:
    platform: template
    value_template: >
      {{ states('sensor.vision_security_zp3111_multisensor_4in1_temperature') | float > 89.9 and
         is_state('switch.media_closet_fan_switch', 'off') }}
  action:
  - service: switch.turn_on
    data:
      entity_id: switch.media_closet_fan_switch
  - service: notify.ios_my_iphone
    data:
      title: Media Closet Fan
      message: Media closet too warm, turning fan on

I am cooling the closet now to verity that notify first ordering works when the sensor is causing the change.

Someone asked for this along the way. This is a ge zwave inwall paddle switch.

{
  "node_id": 4,
  "value_index": 0,
  "value_instance": 1,
  "value_id": "72057594109837312",
  "friendly_name": "Media Closet Fan"
}