I am struggling to get an automation to work properly.
My goal is to check every 5 minutes if my smartphones are still connected to the WIFI network.
This should not be done outside a specific timeframe - After midnight, until 7 AM in the morning.
- id: Check if phones are still online
alias: Check if phones are still online
trigger:
- platform: time
# hour: '/1'
minutes: 5
seconds: 0
condition:
condition: and
conditions:
- condition: state
entity_id: group.devices
state: 'home'
- condition: time
before: 01:00:00
after: 07:00:00
action:
- service: switch.turn_off
data:
entity_id: switch.blue_iris
I’m not sure you’re going about this the best way, but to help with what you currently have…
First, you need to change minutes: 5 to minutes: '/5'. What you have will trigger once an hour at 5 minutes past the hour, whereas the latter will trigger every 5 minutes.
Next, entity_id: group.devices might need to be entity_id: group.all_devices. The latter is an automation group maintained by the device_tracker component that contains all defined device_tracker entities. If you’ve created your own group named group.devices, then what you have is fine.
Next, you said it should not happen outside the period from midnight to 7 AM, which I guess means it should happen during the period from midnight to 7 AM. But what you wrote will only allow it to happen from 7 AM until 1 AM (i.e., during the day and spanning midnight.) So I’m not really sure what you want. If you do want it to only work from midnight until 7 AM, then the time condition should just have before: 07:00:00. Or if you want it to only work from 7 AM until midnight then the time condition should just have after: 07:00:00.
Now, regarding the ultimate goal of the automation, can you explain that (instead of your current design/implementation)? I suspect what you might want is to turn off switch.blue_iris whenever anyone comes home between midnight and 7 AM. If so, there’s a much more efficient way to code that. Or if it’s something else, still, there’s almost always a better way to write an automation than to have it periodically polling (i.e., make it event driven.)
My ultimate goal is to do not activate the blue_iris switch during nighttime.
From midnight to 7AM in the morning.
Outside that time frame I want that my homeassistant checks every 5 minutes if my devices are still connected to my WIFI network.
The blue_iris switch sends an mqtt command to my blue iris software, telling it that the devices are at home but they do not need to adjust the profiles of BlueIris anymore since I want specific cameras to be active during I sleep.
If you really need to turn off switch.blue_iris every 5 minutes between 7 AM and midnight, as long as someone is home, then:
- id: Check if phones are still online
alias: Check if phones are still online
trigger:
platform: time
minutes: '/5'
seconds: 0
condition:
- condition: state
entity_id: group.devices
state: 'home'
- condition: time
after: 07:00:00
action:
service: switch.turn_off
entity_id: switch.blue_iris