How to do not trigger event if last known state/value was the same?

Hi there,

I got a humidity sensor running, that is sending me a notification if the humidity i over 70%, and another one when it comes back under 70%.

But i got the problem that for some reason I have to restart my zigbee2mqtt docker container, because it simply stops sending data to HA. To fix this, I’m restarting the zigbee2mqtt container once per hour.

What happens is, that I’m getting the notification for the humidity every time the container restarts, even the value is still under <70%.

Is it possible to make a condition, that HA won’t send a notification, if the current state, like <70% humidity, was already there before the container restarted?

My current config:

type: humidity
platform: device
device_id: e57c23449200d09b7251003d8cdf7cd3
entity_id: sensor.0x00158d000802c0a9_humidity
domain: sensor
above: 70
for:
  hours: 0
  minutes: 5
  seconds: 0

service: telegram_bot.send_message
data:
  message: humidity over 70%

Use trigger from: to:

thank you.

i will try that

i changed it to this:

platform: state
entity_id:
  - sensor.0x00158d000802c0a9_humidity
from: "70"
to: "69"
attribute: humidity
for:
  hours: 0
  minutes: 0
  seconds: 0

now its not triggering at all if the humidity gets from over 70 to under 70%

Using that it will only trigger if the sensor goes from exactly 70 to exactly 69. So if it starts at 71 it won’t trigger, and if it ends at 68 it won’t trigger. I’d suggest instead a number state trigger using the above: and below: options. This is similar to what you were doing before, but maybe you need to do it as a numberic state trigger. Actually, now that I’m looking closer at your code snippet, that looks like a sensor configuration. Are you doing this from an automation? If so, you might need to check your YAML (or use the GUI to construct the trigger for the automation), as it doesn’t look like what I’d expect to see in an automation.

trigger:
  - platform: numeric_state
    entity_id: sensor.0x00158d000802c0a9_humidity
    below: 70
    for:
      hours: 0
      minutes: 5
      seconds: 0
action:
  - service: telegram_bot.send_message
    data:
      message: 'humidity over 70%'

i came to the same solution 30min ago, im waiting for it to trigger, so i can see if it works.

I created it with the GUI, and then i swaped the GUI to YAML editor and copied the code. so its only the “trigger” part.

It likely happens because the state briefly changes to “unavailable” when the docker container is restarted.
So in the condition of the automation, use a template:

{{ trigger.from_state.state not in ['unavailable','unknown'] }}

will stop the automation triggering if the previous state was either unknown or unavailable.