Thanks for sharing the example.
Could you explain why itâs needed to have a separate 3rd automation - wonât it work if in the 2nd one we turn off the input_boolean
as the last action?
I presume that people are copying code from there - could you take a look at my comments as well?
Iâve tried several different ways to resolve this with no luck. This automation worked prior to me upgrading to the latest version of hassio. Did something change between the versions?
Thanks.
Why do the first two automations have the same id
?
Make them different.
Just for fun, Iâll add my own version of a âmotion-activated light that automatically turns off but only if it was activated by motionâ.
- alias: 'Light Auto On'
trigger:
platform: state
entity_id: binary_sensor.backyard_motion
to: 'on'
condition:
- condition: template
value_template: "{{ state_attr('sun.sun', 'elevation') < 0 }}"
- condition: state
entity_id: switch.backyard_lights
state: 'off'
action:
- service: homeassistant.turn_on
entity_id:
- input_boolean.your_switch_auto_on
- switch.backyard_lights
- alias: 'Light Auto Off'
trigger:
platform: state
entity_id: input_boolean.your_switch_auto_on
to: 'on'
for:
minutes: 3
action:
- service: homeassistant.turn_off
entity_id:
- input_boolean.your_switch_auto_on
- switch.backyard_lights
lol. I donât use ids as they are useless unless (I presume) one uses Automation Editor - if you have id and alias, the latter is always used so whatâs the point in using id?
experimented just yesterday with aliases - they are used to generate object_id
and act as friendly_name
in the same time (with spaces converted to underscores etc) and there is no way to set a friendly_name
it via customise.yaml (didnât work for me) so basically there is no way to give your automation a nice name and know the exact name of your automation (to use it in service call, for example) as to be able to do that one need to know the HA conversion rules (which may change in the future as itâs internal thing).
I might be wrong though but thatâs how I see it now.
if you use templates, how about reducing conditions in the on
automation to
- condition: template
value_template: >
{{
state_attr('sun.sun', 'elevation') < 0 and
is_state('switch.backyard_lights', 'off')
}}
?
UPDATE: however, it depends on what camp are you in according to this discussion
Sure, why not.
As for the id
, it is, as you mentioned, used by the Automation Editor. Thatâs the identifier it uses to uniquely identify each automation. I donât use the Automation Editor but I imagine it may be unhappy when it encounters two or more automations using the same identifier. I donât know if it has any bearing on JohnBâs reported problem but, in the interests of disambiguation, it would be best if the automations have unique identifiers.
Iâll try giving them a unique id to see if that soles the problem. The lights turn on on motion from the ring camera, but do not turn off after 1/3 minutes. I used 1 minute for testing.
try one of the proposed solutions. if it doesnât work, create a new topic as I suggested earlier.
So that no matter how the switch/light/whatever is turned off the boolean is turned off. Otherwise if itâs turned off manually, or by another automation, itâll remain on.
And why do we need this feature (remain on) considering it was created to indicate the fact an automation turned the light on? Shouldnât it be tied to that automation as it might cause very weird side effectsâŚ
Do it your way and see how it works for you
The way Iâve documented it is how I use it - works just fine for me with no weird side effects
I will. The thing is people copy your example so if there is a problem, it becomes their as well
I didnât say it doesnât work, just pointed out the 3rd automation should be incorporated into the 2nd so itâs less code/less room for error/easier to understand and maintain - win-win-win situation.
There will be no weird side effects unless something like this happens
So potentially it might get stuck and disrupt your light automation.
My point is simple - if the flag is for lights only, it should be controlled by lights automations only or youâre asking for troubles.
If itâs controlled only by lights automation, itâs enough tu turn it off when the automation switches the light off as itâs over.
Yes, there are cases when a flag is used to indicate that one of automations is controlling the lights and that means other automations should wait/not trigger, but itâs not the case here so again, youâre asking for troubles or overcomplicating your config.
But Iâm not insisting
I like your solution. I changed it a bit because yours always shuts off after 3 minutes, even if the motion sensor is on. My turn off routine is :
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_kitchen_occupancy
to: 'off'
condition:
condition: state
entity_id: input_boolean.wled
state: 'on'
action:
- service: homeassistant.turn_off
entity_id:
- light.wled
- input_boolean.wled
This then turns off after the motion sensor is off.
No it doesnât. It only turns off if there is no motion for 3 minutes. If there was more motion after 2 minutes and 59 seconds that automation would not trigger.
Your automation just turns off the light straight away with no grace period, which is often undesirable as you will come to see when your automation regularly leaves you in the dark.
No because his turn-off routine does not work based on the motion sensor, but itâs based on the input.boolean. So if âinput.booleanâ âonâ after 3 minutes the âlight is offâ.
The entity_id is irrelevant, itâs the âfor:â statement that causes the system to wait until the state has been the same for a certain amount of time.
I know what âforâ is for. But his always shuts off 3 minutes after turning on the Motion Sensor, no matter if someone is still moving there, but if I (for your sake) put âfor: 3 minutesâ in it, mine will turn off 3 minutes after the Motion Sensor is off. I tried it with âfor: 10 secondsâ and the Motion Sensor was still active but the light went off.
Then something else is wrong with your configuration.
Hello all, I want to start by telling you that I am new to HA and this is my first automation.
Let me tell you about the setup, I have a bathroom windows that is actioned by a motor, with 2 relays. Relay1 ON, Relay2 OFF the window will open, Relay1 OFF, Relay2 ON windows will close, Relay1 ON and Relay2 ON windows stops (also used for close/open position).
What do I want to achieve is a way to prevent the automation to run multiple times when the trigger value is above the value configured using input_bolean
.
Here is the open automation:
alias: Bathroom window open
description: open bathroom windows
trigger:
- platform: numeric_state
entity_id: sensor.bathroom1_si7021_humidity
for: '00:01:00'
above: '50'
condition:
- condition: state
entity_id: input_boolean.bathroom_manual
state: 'off'
action:
- type: turn_on
device_id: 030eab3206bc4ddcf775ca7b0497500e
entity_id: switch.bathroom1_2
domain: switch
- delay:
hours: 0
minutes: 0
seconds: 4
milliseconds: 500
- type: turn_off
device_id: 030eab3206bc4ddcf775ca7b0497500e
entity_id: switch.bathroom1_2
domain: switch
- service: input_boolean.turn_on
target:
entity_id: input_boolean.bathroom_window
mode: single
Here is the close automation:
alias: Bathroom window close
description: close bathroom window
trigger:
- platform: numeric_state
entity_id: sensor.bathroom1_si7021_humidity
for: '00:10:00'
below: '40'
condition: []
action:
- type: turn_on
device_id: 030eab3206bc4ddcf775ca7b0497500e
entity_id: switch.bathroom1
domain: switch
- delay:
hours: 0
minutes: 0
seconds: 12
milliseconds: 0
- type: turn_off
device_id: 030eab3206bc4ddcf775ca7b0497500e
entity_id: switch.bathroom1
domain: switch
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.bathroom_window
- input_boolean.bathroom_manual
mode: single
The problem is that when the condition is set, the automation is not triggered any more, regardless the state of input_boolean.bathroom_manual
state, on or off.