Toggle a Hue Go for a specific color or scene?

I want to configure a flic button as follows.
Single press = toggle hue go white on/off
Double press = toggle hue go red on/off

If I assign a scene to change the color it turns on but not off since there is no toggle option.

If I use toggle, it’s just on/off for last setting. I tried adding data but that makes it just stop working.

Is there a way to do this?

This Issue seems to request what I need but it was closed without implementing it.
https://github.com/home-assistant/home-assistant/issues/4360

I don’t understand the workaround but I think it will not work because it will fix to one color. I want to basically toggle red and toggle white. Another option would be toggle a scene. I can turn scenes on/off with Amazon echo and Smart Things but I can only find turn scene on in HASS no turn scene off or more specifically toggle scene.

I do something similar here: https://github.com/Danielhiversen/home-assistant_config/blob/master/automation/audio.yaml#L154-L159

@Danielhiversen Thanks for another example. That seems very close to what I want to do but I don’t understand how the “condition” applies the true or false to the action. The action looks to me like it turns on the media player, sets the volume, reads the new and no sure what the last homeassistant.turn_on service does.

Does this act like a toggle?

I have the following which turns the light on RED when I single press. I am trying to change this to a toggle.

  • alias: ‘Toggle BedSide Light RED on/off’
    trigger:
    platform: event
    event_type: flic_click
    event_data:
    button_name: flic_80e4da717c9a
    click_type: single
    action:
    service: light.turn_on
    entity_id: light.Bedside
    data:
    brightness: 40
    rgb_color: [ 255, 0, 0]
    color_temp: 369

BTW: Does HASS have to be restarted every time you edit an automation? It makes trial and error cumbersome. Wondering if there is a better way.

UPDATE:

I thought I had this figured out. I think the condition decides if rule should take action. So I tried the following.

  • alias: ‘Toggle BedSide Light RED on if off’
    trigger:
    platform: event
    event_type: flic_click
    event_data:
    button_name: flic_80e4da717c9a
    click_type: single
    condition:
    • condition: template
      value_template: >
      {% if is_state(‘light.flic_80e4da717c9a’, ‘on’) %}
      false
      {% else %}
      true
      {% endif %}
      action:
      service: light.turn_on
      entity_id: light.Bedside
      data:
      brightness: 40
      rgb_color: [ 255, 0, 0]
      color_temp: 369
  • alias: ‘Toggle BedSide Light off if on’
    trigger:
    platform: event
    event_type: flic_click
    event_data:
    button_name: flic_80e4da717c9a
    click_type: single
    condition:
    • condition: template
      value_template: >
      {% if is_state(‘light.flic_80e4da717c9a’, ‘off’) %}
      false
      {% else %}
      true
      {% endif %}
      action:
      service: light.turn_off
      entity_id: light.Bedside

But this results in the light flashing on and then back off with every press. I think because of timing. The first rule fires with the light off so it turns on, then the second rule fires and since it is now “on” it turns off.

I need to stop the other rule once one is satisfied. I think…

OK I figured this all out. Here are the steps I took in case another newbie stumbles on this thread :slight_smile:

-First I added imports for a folder of automations and a folder of scripts to my configuration so I can make a clean config with manageable files.

automation: !include_dir_merge_list automation
script: !include_dir_merge_named script

Then I created the scripts needed to toggle a hue color in a file I chose to call flic_scripts.yaml placed in the script folder

toggle_red_bedside:
  sequence:
  - service_template: script.toggle_red_bedside_{% if is_state('light.Bedside', 'off') %}on{% else %}off{% endif %}

toggle_red_bedside_on:
  sequence:
      - service: light.turn_on
        entity_id: light.Bedside
        data:
          brightness: 40
          rgb_color: [ 255, 0, 0]
          color_temp: 369

toggle_red_bedside_off:
  sequence:
      - service: light.turn_off
        entity_id: light.Bedside

Then I created my automation to assign the flic button press to the primary script which makes the decision to call on or off. I called this flic.yaml in the automations folder.

- alias: 'Toggle BedSide Light RED on/off'
  trigger:
    platform: event
    event_type: flic_click
    event_data:
      button_name: flic_80e4da717c9a
      click_type: single
  action:
    service_template: script.toggle_red_bedside
1 Like

Thanks! This worked perfectly.

Has anyone worked out how to generalise this workaround so that the toggle script can be used on any of the lights rather than having to have a separate script for each light you wan to toggle.

I am imagining the passing of a parameter to the script of the light to be toggled but am lost as to how to code it.

Something like:

action:
  service_template: script.toggle_light
  data:
    thislight: light.bedroom

Use data_template im the action. Take a look at this thread: