I am using input_booleans to trigger automations to run scripts, for example:
- alias: Bedroom lights
initial_state: on
trigger:
platform: state
entity_id: input_boolean.lampor_sov
to: 'on'
action:
- service: script.turn_on
entity_id: script.lights_on_sovrum
I want these input_booleans to always know the status lights_on or lights_off, so that I can have my Custom UI tiles indicate on/off and a button press take the appropriate action, i.e. turn lights on or off. This would be fine if I was only using these input_booleans as switches, but as I am also using time triggered automations for my lights the input_booleans often doesn’t know the state of the lights.
I am considering a couple of different approaches to this:
Have the script put the input_boolean in the correct state after turning lights on or off or set the status of my input_boolean according to a group of lights (group.bedroom_lights). But my question here would be if this will trigger a loop of automations triggered by the input_boolean going to e.g. ‘on’ like in the example above?
Is there a better way to achieve the functionality I am looking for? Below is a screenshot of how my light buttons look like:
I am struggling to see how I would use that in my scenario. How will the switch know if I changed the lamps through a time triggered automation? And what should I use as turn_on/turn_off action?
I got it now! I will have my time triggered automations set input_boolean to on/off instead. That way, the input_boolean will always trigger my light scripts and be in the (hopefully) correct state corresponding to my lamps. I will try and report back.
value_template: “{{ is_state(‘sensor.skylight’, ‘on’) }}” displays the state of the device on the switch. So the switch is conditionally set in a way. It’s what you would want.
I have done my automations now by assigning an input_boolean to every lamp or lamp group and let the input_boolean trigger my automations. This works really well and has made my code much cleaner and easier to read. By including the input_booleans in the recorder, they will also remember the last state when restarting HA.
I’m looking to do this same thing - So do you basically have 4 automations setup per light? One to check when the input_boolean is turned on and one when input_boolean is turned off (pressing the custom ui tiles) and then 2 more for when your other automations turn the lights on/off?
I feel like there has to be a better way to do this.
No, I only have two automations per light or light group. By adding input_boolean to the recorder, they remember their last state and I try to make sure that every light change is triggered by an input_boolean.
There may be better solutions to this, but the code for this is really simple to follow. So when I have e.g. an afternoon automation, I let that automation change the state of the input_booleans, which in turn trigger the automations for the respective light/group.
So one more question - With this method, you’re not able to turn on bulbs with other options are you? For instance, I have an automation that turns on 1 bulb only to like 10%. Is it possible to achieve that when flipping the input_booleans?