Skip to content

Instantly share code, notes, and snippets.

@swilson
Last active November 23, 2020 17:53
Show Gist options
  • Save swilson/3b692802041e01e73415330762f7035d to your computer and use it in GitHub Desktop.
Save swilson/3b692802041e01e73415330762f7035d to your computer and use it in GitHub Desktop.
Home Assistant python script to check for dead Z-Wave devices
checkTime = datetime.datetime.now() - datetime.timedelta(hours=24)
for entity_id in hass.states.get('group.zwave').attributes['entity_id']:
entity = hass.states.get(entity_id)
if entity is not None:
lastSeen = datetime.datetime.strptime(entity.attributes['receivedTS'][:-5], '%Y-%m-%d %H:%M:%S')
if entity.attributes['is_failed'] or lastSeen < checkTime:
msg = entity.attributes['friendly_name'] + ' is AWOL'
logger.error('%s', msg)
service_data = {'message': msg}
hass.services.call("notify", "notify_devices", service_data, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment