Restart Nest Integration if Log entry is over 1 hour old

I’ve noticed that my google nest integration is not polling correctly from the API. On further investigation I notice that this is a known issue. It gets fixed by reloading the integration. Is there a way to automate this restart if the logbook entry on an entity from the integration is not updated in X minutes or hours?

I have been able to solve this through a bit of trial and error.

Step 1) Create a helper that records the time that the entity was last updated. Helper Type ‘Date and/or Time’ then make sure input type ‘Date and Time’ is selected.

Step 2) create automation that updates the helper created in step 1

Use below Yaml for the automation code

alias: Update Nest Last Updated Helper
description: “”
triggers:

  • entity_id: [entity id of one of your nest thermostats it will start climate. ]
    trigger: state
    actions:
  • target:
    entity_id: [entity if of the helper you just created it will start input_datetime. ]
    data:
    datetime: “{{ now().isoformat() }}”
    action: input_datetime.set_datetime
    mode: single

Step 3: creat automation to resart nest automation

Use the below Yaml which will check your helper every 5 mins to see if it is over 1 hour old

alias: Reload Nest Integration if No Update in 1 Hour
description: “”
triggers:

  • minutes: /5
    trigger: time_pattern
    conditions:
  • condition: template
    value_template: >
    {% set last = states(‘input_datetime.XXX [from step 1]’) %} {% if
    last in [‘unknown’, ‘unavailable’, None] %}
    false
    {% else %}
    {% set last_dt = strptime(last, ‘%Y-%m-%d %H:%M:%S’) %}
    {{ (now().replace(tzinfo=None) - last_dt).total_seconds() > 3600 }}
    {% endif %}
    actions:
  • action: homeassistant.reload_config_entry
    data:
    entry_id: YYY [you can find this be navigating to Settings-Devices and Services-Google Nest under integration entries click the three dots next to the entry you want to restart click download diagnostics. The entry_id will be the string of numbers and letters just before .json at the end of the file name.
    mode: single