Sensor state change trigger


Looking for a way how to trigger an action (automation) on sensor change to any new state (I have on/off/offline of my electrical boiler). Currently, I can solve by adding 3 separate automation with triggering by each of the states. But what if there maybe better way?

1 Like

Yes, you can change it up to make it 1 automation, but you don’t really need to unless you just really want to.

You remove the part of your trigger that says to or from or state so it instead is triggered by any change in the sensor. Then, in your action you do can use sevice_template and use a template to call a script based on the state of the sensor. So now you would have 1 automation that can trigger different scripts based on the value of the sensor anytime the sensor value is updated.

Honestly though, id recommend just keeping what you have. You can separate the 3 automations into their own file if you want to clean things up.

Well… i think this is what you are looking for:

    - platform: state
      entity_id: sensor.speedtest_download

Change speedtest download to your own sensor entity name.

Out of curiosity - how did you integrate (I believe) in HA? Is this a script which is running from time to time and setting a sensor state? (if this is possible form within a python script)

I’m updating it every hour:

- platform: speedtest
  server_id: 11615
  minute: 00
#    hour:  #can be used on specific hours only
#      - 6
#      - 13
#      - 17
    - ping
    - download
    - upload

You can use in automation as a trigger for example if the numeric_state is going below some threshold …

Thank you.I was not aware that there was a built-in speedtest platform (I learn everyday with HA)