How to use toggle and go to full brightness when turning on

I have a switch on the wall that can invoke a script and I use it to toggle a group of hue lights. Now, I also use scenes that put this group of lights in low brightness (evening scene). The problem is that the next morning, when I press the button to toggle the state of the lights, they come back up with low brightness (as the evening before). I want them to be full brightness again. Basicly, a toggle that goes back to full brightness when turning on.

It seems that I can’t add additional parameters to the toggle function, as it is possible with turn_on. I’ve opened https://github.com/home-assistant/home-assistant/issues/4360 for that.

Is there a workaround however? This seems like a basic feature, so maybe I’m missing something.

I don’t have hue lights, so I’m not sure if it will work for you, but the zwave bulb that I have has a setting in openzwave to either turn on at the last dimmer setting or turn on to full brightness. You might look into the documentation for your hue bulbs to see if something like that exists.

The HUE does that when it loses power, but I don’t want that since I need to be able to turn them on again from HASS.

I’ve found a workaround:

# Living room [- ] (booglamp toggle)
eltako_3:
  sequence:
  - service_template: script.eltako_3_{% if is_state('light.booglamp', 'off') %}on{% else %}off{% endif %}
eltako_3_on:
  sequence:
  - service: light.turn_on
    entity_id: light.booglamp
    data:
      brightness: 254
      rgb_color: [ 255, 199, 116]
      color_temp: 369
eltako_3_off:
  sequence:
  - service: light.turn_off
    entity_id: light.booglamp

@michaelarnauts where does this workaround go? I am trying to create an action which toggles a hue light on with red color if off or off if on.

I think you are creating a service here but I don’t know were to place it in the config. I tried adding it to my automation config but it keeps throwing errors about syntax. So now I am wondering if it belongs someplace else.

SOLVED: Never mind. I figured this out. I posted my full solution here in case anyone is viewing this thread later and wants to see what I figured out.

I have the problem when switch on the Hue on the wall swich manually.
Hue Light always goes to the low light.

I used automation - everytime the light turns on then goes to bright color.

  • alias: “Set Living Colors to Bright Colour”
    trigger:
    platform: state
    entity_id: group.living_room
    from: “off”
    to: “on”
    action:
    service: light.turn_on
    entity_id: group.living_room
    data:
    brightness: 255
    color_name: white
1 Like

Thanks, my issue wasn’t actually an exact match to this one. I wasn’t having brightness issues but rather wanted to be able to toggle different colors from a physical button. Since toggle still doesn’t accept data for color, brightness etc I needed a workaround. The technique described here fit the bill perfectly.

My universal solution:

script:
  toggle_to_off:
    sequence:
      - condition: template
        value_template: '{{ is_state(light, "on") }}'
      - service: light.turn_off
        data_template:
          entity_id: "{{ light }}"

  toggle_to_on:
    sequence:
      - condition: template
        value_template: '{{ is_state(light, "off") and (as_timestamp(now()) - as_timestamp(states.light[light|replace("light.","")].last_changed) > 3) }}'
      - service: light.turn_on
        data_template:
          entity_id: "{{ light }}"
          brightness_pct: 100

  toggle_to_max:
    sequence:
      - service: script.toggle_to_off
        data_template:
          light: "{{ light }}"
      - service: script.toggle_to_on
        data_template:
          light: "{{ light }}"

And example of usage in automation:

action:
  service: script.toggle_to_max
  data:
    light: light.bedroom
6 Likes

perfect! thanks so much for sharing! is it possible to add more than one light to the automation? I tried

data:
    light:  
- light.bedroom
- light.bedroom_2

but without success.

this has popped up for me at the perfect time! I was literally trying to figure out how to do this yesterday! Thank you :slight_smile:

Data light doesnt support array for now, but you can call multiple service call:

action:
  - service: script.toggle_to_max
    data:
      light: light.bedroom
  - service: script.toggle_to_max
    data:
      light: light.bedroom_2
2 Likes

fantastic, it works!

It’s strange, I can’t get it to work in Lovelace.

  • Script is pasted in my scripts.yaml (I removed the first line with “script:”)
  • I created a simple toggle which shows the icon and status but tap action doesn’t work.
title: Home
views:
  - cards:
      - type: entity-button
        tap_action:
          action: call-service
          service: script.toggle_to_max
          data:
            light: light.office_panel
        hold_action:
          action: more-info
        show_icon: true
        show_name: true
        entity: light.office_panel

Any suggestions?