Hi, I have a problem with the automations: I have set up automations that start with sunrise and sunset that work correctly, using Btcino and Shelly components, therefore dependent on clouds external to HA. The problem occurs when in the Sunrise-Sunset > Sunset-Sunrise interval, if there is a loss of internet connection caused either by a lack of network or electricity, when the connection returns the automation does not start since it is out of the range of the trigger.
Practical automation example: at sunset (7pm) turn on all the lights and close the shutters. If there is no internet connection at 7.00 pm, obviously, the automation will not start; connection returns at 7.30pm the automation doesn’t even start since the trigger went off at 7.00pm. Is there any option to trigger all the automations not started at the predicted time but have them activated as soon as there is a possibility, always taking into account the time range? For example, every time the connection status goes from disconnection to connection, is there the possibility of creating a checksum of the triggers present and if there is any trigger “in the queue” can it be triggered?
Yes I use Sun
Oh OK, I thought you were using some external sunrise/sunset, nevermind. You could probably set up something that checks when the automation was last executed and trigger something off that.
yes I need this but I just don’t know how to do it.
I created an automation with a wan sensor which must reload the automations when the state changes from disconnected to connected but I don’t know if it can work
I can’t use a precise time since the connection loss is random
If you use above_horizon and below_horizon instead of sunrise and sunset, your automation should still trigger when the sensor’s state changes back from unavailable.
I have an automation that runs shortly after a restart, which checks the status of lighting etc. based on the time of day and light levels, and whether there is anyone at home or not. This is intended to deal with power cuts - it doesn’t know what automations have been missed (and by the time power comes back you might not want to run them anyway), but it knows what state the house should be in. The trigger for that is
trigger:
- event: start
platform: homeassistant
If you could monitor your internet connection you could do something similar when it came back after a failure. I use the DNS IP integration to detect this:
It gives you a sensor sensor.myip, so when that goes from unavailable to nn.nn.nn.nn, you’re back. Or you could make a simple template binary sensor:
- binary_sensor:
- name: "online"
unique_id: 9206742f-5493-4a62-b014-f086d9f48d36
state: >
{% if is_state('sensor.myip', 'unknown') %}
off
{% elif is_state('sensor.myip', 'unavailable') %}
off
{% else %}
on
{% endif %}
icon: mdi:server-network
device_class: connectivity
If I were doing this I would probably do a restart anyway after recovering the internet connection, just to tidy up all the error messages.
in fact I would need this, I have a sensor that controls the WAN connection but I don’t know how to use it, could you help me?
alias: Riavvio dopo disconnessione
description: “”
trigger:
- platform: state
entity_id:- binary_sensor.sercomm_vox30_router_stato_della_wan
from: “off”
to: “on”
condition:
action:
- binary_sensor.sercomm_vox30_router_stato_della_wan
- action: automation.reload
metadata: {}
data: {}
mode: single
using this automation this “reset” doesn’t work anyway
automation.reload stops any active automations, then reloads all of them - it doesn’t restart any. It’s only used if you have edited your automations in yaml rather than in the UI.
The thing is, if there has been a break in the internet connection or a power failure, you can’t tell how long HA will have been out of touch with the real world - minutes, hours, days. Most likely you will not want to re-run all the missed automations.
You need to use the sensors available to you (time, light, temperature, occupancy, etc.) to decide what state the house should probably be in and set it to that. The automations will run next time their triggers fire and everything will come back to normal.
In my reset automation I more or less switch everything off, then turn things on again if they are needed (some lights are always on at night, for example, so if it’s dark they are switched on).
In the long term you can reduce your reliance on the internet by getting rid of cloud-based integrations and by introducing devices which don’t use wi-fi - Zigbee, for example. But that’s a big and expensive project.
When you post code, please do it as preformatted text (</> in the toolbar). Spaces are important and simply cutting and pasting removes some of them.
This is the code of my automations, what could I change to do what you say?
I hadn’t thought that when the connection is lost, obviously all the automations including the reset one are lost. I’m using external clouds since I only discovered HA after purchasing all the switches.
- id: '1691343194760'
alias: All Light ON
description: Accensioni luci tramonto
trigger:
- platform: sun
event: sunset
condition: []
action:
- type: turn_on
device_id: d58ecb37d5fbaa27f5719cee3ca1aed7
entity_id: 8798aa65237197c7fb6fc6fe50b3acb6
domain: switch
- type: turn_on
device_id: 990455dd233bc86d3edde63370b563d3
entity_id: b7ef68ac3e79ce49f41c2b05a21c5d33
domain: switch
- type: turn_on
device_id: 3da13af0c17b39f1de77354988ecb91c
entity_id: cfeceede43cff40be6da3b64f342ab5e
domain: switch
- type: turn_on
device_id: 1576a467eeb8439d010bac09dc6ed0c4
entity_id: 2688a48dc11a7956324110355dab0007
domain: switch
- type: turn_on
device_id: dcff8876c70b73c24a997c47e5426d92
entity_id: be57afed5048f5b495e56d6a0f8c3ff2
domain: switch
mode: restart
- id: '1691343307649'
alias: Chiusura tapparelle
description: ''
trigger:
- platform: sun
event: sunset
offset: 0
condition: []
action:
- device_id: d0eabaae53d3faf0cd770b951acbdb61
domain: cover
entity_id: 0efab5c4f457b200175ce8a8fbc4009d
type: set_position
position: 10
- device_id: bcc41ae4c65c0a3ae294da796b50cbf7
domain: cover
entity_id: 346b4dc741ad1ea6fd0d9a6abef05680
type: close
mode: restart
- id: '1691343489380'
alias: Luci EXT OFF
description: ''
trigger:
- platform: sun
event: sunrise
condition: []
action:
- type: turn_off
device_id: d58ecb37d5fbaa27f5719cee3ca1aed7
entity_id: 8798aa65237197c7fb6fc6fe50b3acb6
domain: switch
- type: turn_off
device_id: 3da13af0c17b39f1de77354988ecb91c
entity_id: cfeceede43cff40be6da3b64f342ab5e
domain: switch
mode: restart
- id: '1691343945251'
alias: Luci retro OFF
description: ''
trigger:
- platform: time
at: '23:00:00'
condition: []
action:
- type: turn_off
device_id: 990455dd233bc86d3edde63370b563d3
entity_id: b7ef68ac3e79ce49f41c2b05a21c5d33
domain: switch
mode: restart
- id: '1691344258471'
alias: Luce Giardino OFF
description: ''
trigger:
- platform: time
at: '23:59:00'
condition: []
action:
- type: turn_off
device_id: 1576a467eeb8439d010bac09dc6ed0c4
entity_id: 2688a48dc11a7956324110355dab0007
domain: switch
mode: restart
- id: '1708883581036'
alias: Lampada UV On
description: ''
trigger:
- platform: time
at: '16:00:00'
condition: []
action:
- type: turn_on
device_id: da92d98894c7efdc3983f0037773433c
entity_id: 5a4d77f21161567abbb0647aae3d0aac
domain: switch
mode: restart
- id: '1708883626489'
alias: Lampada UV Off
description: ''
trigger:
- platform: time
at: '22:00:00'
condition: []
action:
- type: turn_off
device_id: da92d98894c7efdc3983f0037773433c
entity_id: 5a4d77f21161567abbb0647aae3d0aac
domain: switch
mode: restart
- id: '1711489848879'
alias: Ventilazione inverter ON
description: ''
trigger:
- platform: numeric_state
entity_id:
- sensor.solarman_radiator_temperature
above: 45
condition: []
action:
- type: turn_on
device_id: 6eb97738a63fe7daba6c6e9957d27a24
entity_id: 0037c74b156ff83f2912abe05ff20dd8
domain: switch
mode: restart
- id: '1711489940309'
alias: Ventilazione inverter OFF
description: ''
trigger:
- platform: numeric_state
entity_id:
- sensor.solarman_radiator_temperature
below: 35
condition: []
action:
- type: turn_off
device_id: 6eb97738a63fe7daba6c6e9957d27a24
entity_id: 0037c74b156ff83f2912abe05ff20dd8
domain: switch
mode: restart
- id: '1726934908920'
alias: Luce cappellina OFF
description: ''
trigger:
- platform: sun
event: sunrise
offset: 0
condition: []
action:
- type: turn_off
device_id: dcff8876c70b73c24a997c47e5426d92
entity_id: be57afed5048f5b495e56d6a0f8c3ff2
domain: switch
mode: restart
- id: '1727531471909'
alias: Riavvio dopo disconnessione
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.sercomm_vox30_router_stato_della_wan
from: 'off'
to: 'on'
condition: []
action:
- action: automation.reload
metadata: {}
data: {}
mode: single
To go back to your original question…
No. There isn’t.
What I am suggesting is a new automation, triggered by a restart or by recovery from an internet outage, which would put the house into an appropriate state.
Do your light sensors say it’s dark? Turn the lights on.
Do the temperature sensors say it’s cold? Turn the heating on.
Do your trackers say there’s nobody home? Don’t do either of those things.
I don’t have a sensor that measures darkness, can this be done through some integration?