Sensor automation triggers once, but doesn't repeat

I’m running a few shell scripts based on some speedtest sensor values. The shell scripts run work consistently when I test from the UI. The state for all of them are on. But they only seem to trigger once, I have to reboot HA before they work again once.

The Start Speed Test and Start Speed Test Light both work. But the Internet Super Slow command doesn’t not trigger on the next speed test run even though the condition is still met.

I have an LED I’m using as a status indicator for my internet speed.

  • Every 15 minutes run shell_command to turn light white (pending speed test)
  • 15 seconds later run speedtestdotnet.speedtest service
  • Update color of speed test based off sensor
- alias: "Start Speed Test"
  trigger:
    platform: time_pattern
    minutes: '/15'
  action:
    - delay:
        seconds: 5
    - service: speedtestdotnet.speedtest
- alias: "Start Speed Test Light"
  trigger:
    platform: time_pattern
    minutes: '/15'
  action:
    - service: shell_command.speed_test_start
- alias: "Internet Super Slow"
  trigger:
    platform: template
    value_template: "{{ states('sensor.speedtest_download')|float < 40 }}"
  action:
    - service: shell_command.speed_test_super_slow

Looks like this user has the same problem: Reload automations

Please format your code to make it easier for others to inspect it.

@123 Sorry about that! Fixed.

From the documentation for a Template Trigger:

The trigger will fire if the state change caused the template to render ‘true’. This is achieved by having the template result in a true boolean expression … Being a boolean expression the template must evaluate to false before it will fire again.

Basically it’s saying that when this template:

{{ states('sensor.speedtest_download')|float < 40 }}

evaluates to true it will trigger the automation. That means sensor.speedtest_download must drop below 40. However, to trigger the automation again, the template must evaluate to false and then to true. That means it must first rise above 40 before falling below 40 to trigger the automation.

Is this the way you expected it to work?

@123 thanks for the clarification. Because I change the status of the LED to indicate the speed test is running, I need to return it to it’s original value again, even if it’s the same as the last run. This must be why it’s not being ran again. Is there a way to override this? Or create a new template that always renders?

@123 apologizes, I’m new to this and wasn’t sure of the limitations. Based off my scenario, what would you suggest?

What exactly is ‘your scenario’? Do you want this kind of behavior:

  • x must be less than 40
  • it triggers when x falls below 40, say to 35
  • it triggers again when x falls from 35 to 30
  • it triggers again when x increases from 35 to 38

If this is what you want, you need the automation to trigger on any change of the sensor, then use a condition to check if it’s below 40.

- alias: "Internet Super Slow"
  trigger:
    platform: state
    entity_id: sensor.speedtest_download
  condition:
    condition: template
     value_template: "{{ trigger.to_state.state | float < 40 }}"
  action:
    - service: shell_command.speed_test_super_slow