Input_boolean to trigger automation to run script - will it loop?

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:
lights_ui_tiles

Try using template switch instead of input boolean.

Hm, I am looking at the example from the template_switch component:

switch:
  - platform: template
    switches:
      skylight:
        value_template: "{{ is_state('sensor.skylight', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.skylight_open
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.skylight_close

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?

why not just use two automation? Use light state as trigger and set the switch accordingly.

Or if possible use MQTT switch and set state topic.

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.

Umm, because the value template for whether its on or off is the state of the device… :roll_eyes:

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.

Ah, that makes sense. I’ll have to change all my timing automations to adjust the input_boolean instead of the lights directly. Thanks!

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?

Yep, but you need to have the input boolean execute a script instead of the light/light group. Then in the script, you set the intensity of the light.