Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automations doesn't trigger sometimes #28108

Closed
Fusseldieb opened this issue Oct 22, 2019 · 16 comments
Closed

Automations doesn't trigger sometimes #28108

Fusseldieb opened this issue Oct 22, 2019 · 16 comments

Comments

@Fusseldieb
Copy link

Fusseldieb commented Oct 22, 2019

Home Assistant release with the issue:
0.100.2

Last working Home Assistant release (if known):
N/A

Operating environment (Hass.io/Docker/Windows/etc.):
Ubuntu Server 18.04 using Hassio within Docker

Integration:

Template Automation

Description of problem:
Sometimes automations don't trigger. It's very rare, but it occurs. In my case, we have a water tank which fills when it's below 80% and only stops when it reaches 100%, but sometimes (rare), it just doesn't trigger and do overfill the tank. Right now as I'm writing this it's happening again. There's nothing wrong with the automation itself, as it works 99% of the time.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- alias: Full tank sensor
  hide_entity: True
  trigger:
    platform: state
    entity_id: sensor.tanklevel
  condition:
    condition: or # I'll leave this here to easily chain more things when/if needed in the future
    conditions:
    - condition: template
      value_template: >-
          # If 100 or over, returns True
          {% set level = states.sensor.tanklevel.state | int %}
          {{ level >= 100 }}
  action:
    # Closes the valve and turns the motor off
    - service: switch.turn_off
      entity_id: switch.tankmotor
    - service: switch.turn_off
      entity_id: switch.tankvalve

Traceback (if applicable):


Additional information:
image
At this time, it still didn't trigger

To remedy this issue temporarily, I've added a automation inside ESPHome that turns the valve off if it reports over 108% to avoid any major problems. At 118% it would overflow (which happened a couple of times before).

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as its been labeled with a integration (automation) you are listed as a codeowner for? Thanks!

@dkagedal
Copy link

Can you use a numeric state trigger instead? Does it make any difference if you do?

@Fusseldieb
Copy link
Author

Fusseldieb commented Oct 22, 2019

Can you use a numeric state trigger instead? Does it make any difference if you do?

Good question.

I've now changed the automation to the numeric state trigger like so:

- alias: Full tank sensor
  hide_entity: True
  trigger:
    platform: numeric_state
    entity_id: sensor.tankslevel
    value_template: '{{ states.sensor.tankslevel.state }}'
    above: 99
  action:
    # Closes the valve and turns the motor off
    - service: switch.turn_off
      entity_id: switch.tankmotor
    - service: switch.turn_off
      entity_id: switch.tankvalve

Let's see... This may take some days to test.

But even if it works, something's off with the template trigger...

@OttoWinter
Copy link
Member

If the device is offline during the action, the automation will fail (i think it would create a log entry in the error log though). That may be an jssue

I'd suggest you add something like persisten_notification.create to check if the automation really does fire or if it's the action that fails.

@Fusseldieb
Copy link
Author

Fusseldieb commented Oct 23, 2019

If the device is offline during the action, the automation will fail (i think it would create a log entry in the error log though). That may be an jssue

It's always online. Maybe it didn't respond or something like that? I don't know for sure.

I'd suggest you add something like persisten_notification.create to check if the automation really does fire or if it's the action that fails.

I can do that, too.

@Fusseldieb
Copy link
Author

Fusseldieb commented Oct 24, 2019

Can you use a numeric state trigger instead? Does it make any difference if you do?

Yesterday it happened again. No difference. The trigger doesn't ... trigger.

If the device is offline during the action

On further inspection this isn't possible, because the percentage sensor and the relays are attached on the same ESP, so...

This problem is not directly related to this sensor: Other things sometimes also don't trigger. I've set the lights in the garden to shut off at a certain hour and it happens that I look in the morning and they're still on. Another automation is there to shut off a valve to another motor after 3 hours and it happened to me more than once that the motor just stays on the whole day.

@Fusseldieb
Copy link
Author

Fusseldieb commented Jan 20, 2020

Still happening with all sorts of automations that depend on time.
Sometimes they trigger, sometimes they don't.

Motors that should turn off after 2 hours just continue running.
Lights that should turn off after 5 minutes sometimes shut off, sometimes don't and are left on until they are turned off manually or triggered again and then finally shut off.
Connection is 100% stable.

HA 0.103.6.

EDIT:
image
In the picture above, the light should turn off after 5 minutes, but sometimes it's on for 10 or even 15 minutes. Other times it doesn't turn off at all.

@Nenodema
Copy link

Nenodema commented Apr 8, 2020

I have exactly the samen problem with temperature (sonoff / mqtt) and humidty (zigbee / mqtt) sensors.

An ugly workaround is to implement a 1 minute time_pattern trigger.

https://community.home-assistant.io/t/automations-doesnt-trigger-sometimes/184026/

@pnbruckner
Copy link
Contributor

@Fusseldieb the template condition in the automation in your original comment is invalid. You can't put a comment inside a template, since it becomes part of the result. That template condition would effectively always evaluate to false (because after being evaluated, converted to lower case and stripped, it will never exactly equal the string 'true'.)

Also, when you removed that condition and changed the trigger to a numeric_state trigger, you should not have used the value_template parameter like that. You should just remove that line from the trigger.

If you are still having trouble, I suggest you add the following to your configuration:

logger:
  default: info
  logs:
    homeassistant.core: debug

Then you'll be able to see (in home-assistant.log) all the state changes of that sensor (and all other entities in the system), as well as when the automation triggers. That will give you all the details you need to understand why the automation triggers or doesn't trigger when you expect it to.

@Fusseldieb
Copy link
Author

@Fusseldieb the template condition in the automation in your original comment is invalid. You can't put a comment inside a template, since it becomes part of the result. That template condition would effectively always evaluate to false (because after being evaluated, converted to lower case and stripped, it will never exactly equal the string 'true'.)

Sorry, but that comment inside the template I inserted here on GitHub, it isn't part of my automation, it was just to explain better. The autionation also triggers fine - but only sometimes.

Also, when you removed that condition and changed the trigger to a numeric_state trigger, you should not have used the value_template parameter like that. You should just remove that line from the trigger.

Oh, okay... Makes sense, I'll remove it later. Note that the autiomation works 100% with the time_trigger, but it's an awkward workaround.

If you are still having trouble, I suggest you add the following to your configuration:

logger:
  default: info
  logs:
    homeassistant.core: debug

Then you'll be able to see (in home-assistant.log) all the state changes of that sensor (and all other entities in the system), as well as when the automation triggers. That will give you all the details you need to understand why the automation triggers or doesn't trigger when you expect it to.

I will!

Thanks for answering!

@stale
Copy link

stale bot commented Jul 11, 2020

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 11, 2020
@stale stale bot closed this as completed Jul 18, 2020
@Fusseldieb
Copy link
Author

Fusseldieb commented Jul 19, 2020 via email

@bsp9493
Copy link

bsp9493 commented Mar 25, 2021

sounds similar to an issue I am having.

I have a template sensor I am trying to use as a trigger within an automation.

variable_sensors:
  sensor:
    - platform: template
      sensors:
# SOLAR TEMP DIFF
        solar_temp_diff:
          value_template: "{{ states('sensor.pentair_airtemp') | float - states('sensor.pentair_soltemp') | float }}"

this sensor updates and reports the expected values, but it will not activate the trigger in the automation.

If I manually trigger the actions within the automation, it works as expected
if I manually change the state of the entity solar_temp_diff using developer tools, my automation works as expected
however, it will not trigger automatically when the value changes naturally.

the automation is as follows (currently using state as a trigger, but I have also tried numeric state). My other automations trigger on time, sun, state (but from sensors created by other integrations - not a template sensor I created in my yaml

alias: pool - solar circ (on/off) @ 20
description: ''
trigger:
  - platform: state
    entity_id: sensor.solar_temp_diff
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ states(''sensor.solar_temp_diff'') | float < 20 }}'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pentair_pooll
      - conditions:
          - condition: template
            value_template: '{{ states(''sensor.solar_temp_diff'') | float >= 20 }}'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.pentair_pooll
    default: []
mode: single

I too am starting to wonder if it is something bigger.

@pnbruckner
Copy link
Contributor

@bsp9493 see my comments above about enabling debug output and checking home-assistant.log for details to see what's really happening in your system.

@bsp9493
Copy link

bsp9493 commented Mar 25, 2021

turned on debug, and watched it for probably an hour (searched as well) and CANNOT see solar_temp_diff showing an update in the logs

I even added an automation to force update of this entity... in that case I see the following

2021-03-25 12:50:30 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=pool - force update of solar_temp_diff, entity_id=automation.pool_force_update_of_solar_temp_diff, source=time pattern>
2021-03-25 12:50:30 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.pool_force_update_of_solar_temp_diff, old_state=<state automation.pool_force_update_of_solar_temp_diff=on; last_triggered=2021-03-25T12:49:30.003577-07:00, mode=single, current=0, id=1616683974481, friendly_name=pool - force update of solar_temp_diff @ 2021-03-25T12:49:09.674747-07:00>, new_state=<state automation.pool_force_update_of_solar_temp_diff=on; last_triggered=2021-03-25T12:50:30.003626-07:00, mode=single, current=1, id=1616683974481, friendly_name=pool - force update of solar_temp_diff @ 2021-03-25T12:49:09.674747-07:00>>
2021-03-25 12:50:30 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=homeassistant, service=update_entity, service_data=entity_id=['sensor.solar_temp_diff']>
2021-03-25 12:50:30 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.pool_force_update_of_solar_temp_diff, old_state=<state automation.pool_force_update_of_solar_temp_diff=on; last_triggered=2021-03-25T12:50:30.003626-07:00, mode=single, current=1, id=1616683974481, friendly_name=pool - force update of solar_temp_diff @ 2021-03-25T12:49:09.674747-07:00>, new_state=<state automation.pool_force_update_of_solar_temp_diff=on; last_triggered=2021-03-25T12:50:30.003626-07:00, mode=single, current=0, id=1616683974481, friendly_name=pool - force update of solar_temp_diff @ 2021-03-25T12:49:09.674747-07:00>>

but again, NO update in the state of solar_temp_diff.

if I change the value manually with developer tools... I see the expected outcome as follows...

2021-03-25 12:56:51 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=pool - solar circ (on/off) @ 20, entity_id=automation.pool_solar_circ_on_off_20, source=state of sensor.solar_temp_diff>
2021-03-25 12:56:51 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.pool_solar_circ_on_off_20, old_state=<state automation.pool_solar_circ_on_off_20=on; last_triggered=2021-03-25T12:54:30.047959-07:00, mode=single, current=0, id=1616695573831, friendly_name=pool - solar circ (on/off) @ 20 @ 2021-03-25T12:49:09.675773-07:00>, new_state=<state automation.pool_solar_circ_on_off_20=on; last_triggered=2021-03-25T12:56:51.823570-07:00, mode=single, current=1, id=1616695573831, friendly_name=pool - solar circ (on/off) @ 20 @ 2021-03-25T12:49:09.675773-07:00>>
2021-03-25 12:56:51 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_off, service_data=entity_id=['switch.pentair_pooll']>
2021-03-25 12:56:51 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=pentair/circuit/541/command, qos=0, retain=False, payload=OFF>
2021-03-25 12:56:51 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.pool_solar_circ_on_off_20, old_state=<state automation.pool_solar_circ_on_off_20=on; last_triggered=2021-03-25T12:56:51.823570-07:00, mode=single, current=1, id=1616695573831, friendly_name=pool - solar circ (on/off) @ 20 @ 2021-03-25T12:49:09.675773-07:00>, new_state=<state automation.pool_solar_circ_on_off_20=on; last_triggered=2021-03-25T12:56:51.823570-07:00, mode=single, current=0, id=1616695573831, friendly_name=pool - solar circ (on/off) @ 20 @ 2021-03-25T12:49:09.675773-07:00>>

so for some reason, that I am unable to track down changes to the state of this entity are NOT being logged even though my sensor is displaying the correct values and showing update as it should.

@pnbruckner
Copy link
Contributor

Not sure what to tell you. If the sensor is updating, then there should be state_changed events for it in the log. I have plenty of template sensors and binary sensors, and they all cause state_changed events in the log when they update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants