Coding Help needed for config temperature senor not change for a period of time

Try to get warning of battery dead of a bluetooth temperature/humidity device. When I try using battery level becames unavailable, it doesn’t work as HA seems always getting last value of the devices before it dead. Now I try working a condition to say if temperature value not moving for 5 hours (unusual), give me the warning. However, not good of python. Here is the coding I attemped. would anyone can help me to correct it?

trigger: state
entity_id:
  - sensor.miaomiaoce_t2_7d7b_temperature
attribute: No change
for:
  hours: 5
  minutes: 0
  seconds: 0

trigger: state
entity_id: sensor.miaomiaoce_t2_7d7b_temperature
for:
  hours: 5

It’s not Python. You’re looking for the state to not change for 5 hours. The Attribute field is for when you’re looking at one of the sensor’s attributes — as you’re not doing that here, it should be left blank (see here for more info).

Alternatively, protecting against a very constant temperature for 5 hours:

trigger: template
value_template: "{{ (now() - states['sensor.miaomiaoce_t2_7d7b_temperature']['last_reported']).total_seconds() > 18000 }}"

That’s a Jinja template in the {{ ... }} — the trigger will fire when the template turns from false to true, which will happen when the last_reported property of the sensor becomes more than 18000s (5 hours) old.

1 Like

thanks. However, I try testing to put time of 1 min. After copy paste your coding with currect senor name. and save it. it didn’t fire up. and check again. It seems HA changed coding automatically as following

trigger: template
value_template: >-
  {{ (now() -
  states['sensor.miaomiaoce_t2_abd9_temperature']['last_reported']).total_seconds()
  > 60 }}

figured out. it is last changed property, not last reported. The working code is below.

trigger: template
value_template: >-
  {{ (now() -
  states['sensor.miaomiaoce_t2_abd9_temperature']['last_changed']).total_seconds()
  > 18000 }}

The state trigger is still not working.

the state trigger works also. As long as it triggered by last changed state once. It will work. :slight_smile:

What version of HA are you running?

HA core 2024.11.1 frontend 20241106.2