Last active
November 23, 2020 17:53
-
-
Save swilson/3b692802041e01e73415330762f7035d to your computer and use it in GitHub Desktop.
Home Assistant python script to check for dead Z-Wave devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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