Trying to monitor a device’s connectivity to my network. it goes down every so often. If connectivity is down I want to re-check every 30 minutes until fixed or and between 9am to 9pm.
Not real sure what I should use for “- service” under “sequence” key word. This is the relevant code…
automations.yaml
----------------
- id: '1629334608935'
alias: connectivity_dvr
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.connectivity_dvr
to: 'off'
for:
hours: 0
minutes: 1
seconds: 0
condition:
- condition: time
after: "09:00:00"
before: "21:00:00"
action:
- alias: repeat 30 minutes until device reset
repeat:
sequence:
- service: binary_sensor.connectivity_dvr
entity_id: binary_sensor.connectivity_dvr
- delay: 00:30:00
until:
- condition: state
entity_id: binary_sensor.connectivity_dvr
state: "on"
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: channel master tv guide server might be down check under TV.
data:
type: announce
method: speak
mode: single
binary_sensor.yaml
------------------
- platform: ping
name: connectivity_dvr
host: 192.168.1.22
scan_interval: 15
That’s not really a thing in HA… but there are a number of other options.
Personally, I would go for an Alert, but it will require a Template binary sensor to handle the conditional logic.
Or, you can use a more brute force method with a Time pattern trigger to poll the state every 30 minutes to see if it has been off for at least 30 minutes.
There isn’t a service for that, it’s already being handled by the condition of the until… but prolonged waits, delays, and loops are generally best avoided.
Also, be aware that your automation will not make the desired announcement in the morning if the connection fails overnight unless it comes back then fails again.
From what I see, you are already pinging your device, otherwise the state can not be down.
so running the script again and again if it is already down doesn’t help
I would define more triggers to do more notifcations every 30 minutes.
if dvr = down for 30 minutes
if dvr = down for 60 minutes
- id: '1629334608935'
alias: connectivity_dvr
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.connectivity_dvr
to: 'off'
for:
hours: 0
minutes: 1
seconds: 0
- platform: state
entity_id:
- binary_sensor.connectivity_dvr
to: "off"
id: off_for_30M
for:
hours: 0
minutes: 30
seconds: 0
- platform: state
entity_id:
- binary_sensor.connectivity_dvr
to: "off"
id: off_for_60M
for:
hours: 1
minutes: 0
seconds: 0
action:
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: channel master tv guide server might be down check under TV.
data:
type: announce
method: speak
mode: single
The automation has nothing to do with pinging the device… that is already happening every 15 seconds based on the sensor configuration you posted above.
You are already pinging the devices, so run a automation to do the same has no added value.
In your logic:
If ping set’s a sensor down for 1 minute → ping again every 30 minutes on top of the current ping action. but send a notification.
In the suggested automation:
If ping set’s a sensor down for 1 minute → send notification
If sensor is down for 30 minutes → send notification
if sensor is down for 60 minutes → send notification