Help writing an automation for a sensor when value does not change

I’m hoping someone will be able to help me write an Automation for the following scenario;

My heating uses Zigbee temperature sensors to monitor temperatures of the rooms and turn on the boiler as and when required. All this is controlled via my Home Assistant and uses various automations to control it.

The problem I have is that occassionaly the sensors lock up at any given temperature, meaning that the boiler will now not turn off as the sensor does not read any temperature change. This then requires a manual intervention to knock the boiler off and or reset the sensor.

The Automation I’m looking for will recognise that the temperature sensor has not changed value for a given period of time. This will then trigger a notify action to tell me.

I’m not sure how to tell the ‘Trigger’ to be a no change in numerical state.

- id: '1613417034253'
  alias: Sensor frozen
  description: 'notify if temp sensor frozen'
  trigger:
  - platform: numeric_state
    entity_id: sensor.temperature_10
    for: '30'
    above: '20'
  condition:
  - condition: state
    entity_id: switch.switch_2
    state: 'on'
  action:
  - service: notify.mobile_app_dave_s_phone
    data:
      message: Sensor Frozen - Reset required
      title: Sensor Frozen

In the above ‘Switch 2’ is the boiler.

Currently the trigger is set for if the temperature is above 20 for 30mins. But need this to be at any temperature for a period of time ie 30 mins.

Any help would be greatly appreciated

This will trigger if your sensor has not changed for 30 minutes:

trigger:
  - platform: template
    value_template: "{{ as_timestamp( utcnow() ) | int > as_timestamp( states.sensor.temperature_10.last_changed ) | int + 30*60 }}"
1 Like

Hi tom_I

Thanks for the suggestion! I’ll try testing it. Cheers.

I’d really like to understand that level of coding, so more research required for me!

Petro wrote a great reply on state objects and their properties:

The template takes the time and date the sensor last changed, converts this to a timestamp, which is just the number of seconds since the last Unix epoch, ( 00:00:00 UTC on 1 January 1970 ). We add 30*60 seconds to it and check to see how that compares to the timestamp of the UTC time now. If the now timestamp is a bigger number of seconds, then your sensor has not changed for 30 minutes.

1 Like

This s as a almost exactly what I am trying to do but I am struggling to get it to work.

The code I have so far is


alias: Hot Water Boost Failure (Duplicate)
description: ''
trigger:
  - platform: state
    entity_id: timer.hot_water_boost
    to: active
condition:
  - condition: template
    value_template: >-
      {{ as_timestamp( utcnow() ) | int > as_timestamp(
      states.sensor.hot_water_temperature.last_changed ) | int +2*60 }}
action:
  - service: notify.mobile_app_my_iphone
    data:
      message: Water Temperature failed
mode: single

I am trying to boost my hot water for about 30 minutes and have the automation check if the temperature of the hot water is increasing. If the temperature does not increase by a certain amount in 15 minutes for example, send me a notification or maybe do something else.

The platform: template looks like it can do what I am trying to accomplish but I’m struggling to implement it.

Any help would be very much appreciated.