Notifies me when device is online again and eliminates short-term unavailable states. It sometimes happens that a device is unavailable for several seconds and then goes online again. These I would like to ignore. It means to notify me when devices are unavailable for 5 minutes and then go online again.
Then I would like to replace the list of entities by a group of entities (approx. 50 devices). But then I don’t know how to set the template to be able to notify me with the specific name of a device.
@Tomm206
I use the Ping service to monitor all my devices. Below you’ll find my code for OFFLINE and ONLINE events for my mission critical devices. If you have any further questions about my code, just ask.
##########################################################
## Notify if a critical device goes offline
##########################################################
- id: a_critical_device_goes_offline
alias: A Critical Device goes Offline
initial_state: true
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.ping_cloud_key
to: 'off'
for:
minutes: 1
- platform: state
entity_id: binary_sensor.ping_vera_secure
to: 'off'
for:
minutes: 1
- platform: state
entity_id: binary_sensor.ping_xfinity_router
to: 'off'
for:
minutes: 1
action:
## Event Log start
- service: script.turn_on
entity_id: script.notify_logs_event
data_template:
variables:
var_type: "automation.a_critical_device_goes_offline"
var1: "Trigger {{ trigger.to_state.attributes.friendly_name }}"
var2: "{{ trigger.to_state.attributes.friendly_name }} has gone OFFLINE."
## Event Log End
- service: script.turn_on
entity_id: script.notify_hass_a_critical_device_goes_offline
data:
variables:
var_device_name: "{{ trigger.to_state.attributes.friendly_name }}"
- service: script.turn_on
entity_id: script.notify_push_a_critical_device_goes_offline
data:
variables:
var_device_name: "{{ trigger.to_state.attributes.friendly_name }}"
#
##########################################################
## Notify when a critical device returns online
##########################################################
- id: a_critical_device_returns_online
alias: A Critical Device returns Online
initial_state: true
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.ping_cloud_key
to: 'on'
for:
minutes: 1
- platform: state
entity_id: binary_sensor.ping_vera_secure
to: 'on'
for:
minutes: 1
- platform: state
entity_id: binary_sensor.ping_xfinity_router
to: 'on'
for:
minutes: 1
action:
## Event Log start
- service: script.turn_on
entity_id: script.notify_logs_event
data_template:
variables:
var_type: "automation.a_critical_device_returns_online"
var1: "Trigger {{ trigger.to_state.attributes.friendly_name }}"
var2: "{{ trigger.to_state.attributes.friendly_name }} has returned ONLINE."
### Event Log End
- service: script.turn_on
entity_id: script.notify_hass_a_critical_device_returns_online
data:
variables:
var_device_name: "{{ trigger.to_state.attributes.friendly_name }}"
- service: script.turn_on
entity_id: script.notify_push_a_critical_device_returns_online
data:
variables:
var_device_name: "{{ trigger.to_state.attributes.friendly_name }}"
#
You may notice that the times are very short. This was by design, as I wanted a much quicker response for these devices. All other online devices are on a 10 minute duration (bulbs, tvs and other non critical devices).