Having 3 automations seems wrong for such a simple task. (The third one ensures that the light is on if the server restarts). Can you suggest a way to combine those three into one?
The logic is painfully simple: if the sun is below the horizon, the light should be on.
I donât mind doing it by hand, if thatâs the only way. I was able to get this far via GUI, but I think the last bit is wrong:
- id: '1593801439995'
alias: Fan ON when Excess Energy
description: ''
trigger:
- entity_id: binary_sensor.excess_energy
from: 'off'
platform: state
to: 'on'
- entity_id: binary_sensor.excess_energy
from: 'on'
platform: state
to: 'off'
- event: start
platform: homeassistant
condition: []
action:
- condition: state
entity_id: switch.aft_cabin_fan
state: binary_sensor.excess_energy
in this particular case I want the state of switch.aft_cabin_fan to mirror the state of entity_id: binary_sensor.excess_energy
You talked in your first post about lights and sun positions.
You second post talks about fans and energy.
What are you after doing ?
What entity_idâs are involved ?
Logic is exactly the same: binary_sensor (sun in the first case, âexcess_energyâ in the second). I want to set the switch (light in the first case, fan in the second case) to mirror the state of that binary sensor. I canât manipulate the sun, so I am experimenting with excess_energy sorry for the confusion.
it will trigger when the sunâs elevation dips below the horizon. It will also trigger when Home Assistant is restarted when the sun is already below the horizon. That might help you consolidate your first and third automations (that ensure the anchor light is turned on after sunset).
The purpose of marking a post with the Solution tag is to show others how to solve the originally stated problem.
In this case, the Solution post doesnât do that. It contains no triggers for sunrise or sunset and references entities not mentioned in the original problem.
For the benefit of the community, please consider revising your Solution post to show others how you reduced the original three automations.
Dear Taras, I posted the âactionâ bit because that is the only part that I was having problems with, and the only one that is counterintuitive, the rest of the yaml is the same as in my post above, and can be achieved with the GUI. So I didnât want to confuse whomever is going to be reading this, and making an impression that I did the whole thing by hand. Here it is in its entirety:
- id: '1593801439995'
alias: Fan ON when Excess Energy
description: ''
trigger:
- entity_id: binary_sensor.excess_energy
from: 'off'
platform: state
to: 'on'
- entity_id: binary_sensor.excess_energy
from: 'on'
platform: state
to: 'off'
- event: start
platform: homeassistant
condition: []
action:
- entity_id: switch.aft_cabin_fan
service_template: '{% if is_state(''binary_sensor.excess_energy'', ''on'') %}
switch.turn_on {% else %} switch.turn_off {% endif %}'
and btw. your suggestion with numeric_state didnât work. It didnât trigger on the server restart.
This is what you asked in the first post and the automations concerned sunrise/sunset and an anchor light.
Thatâs what Muttley and I volunteered to help you with. Then you posted code that had nothing to do with the first three automations and that confused both Muttley and I and undoubtedly anyone else attempting to follow this topic.
Effectively, your solution post changed the example and wouldnât be the way I would handle multiple triggers based on sunrise/sunset.
Sorry to hear the numeric_state example failed to work for you. I have used it and it works for me.
Final tip before I exit this topic, the service_template can be condensed to this:
this is the first (and only relevant) thread coming up in searches for people searching for help simplifying what OP shows in his first post - the multiple automations needed for achieving such simple looking task like a ânight lightâ when doing it with the GUI
so indeed it would be nice if someone in the know could post a complete solution for such automation using the actual trigger events sunset/rise coming from what the GUI generates. The solution posted is using completely different triggers which a noob (like me) canât adapt to the âsunâ platform (yet).
as a starter - this is what i got for turning a switch on 15 minutes before sunset: