Phillips Hue lights - Return to previous state?

There really needs to be a way for Phillips Hue lights to return back to previous state. This is something that is available in the official Hue API

Let me give some examples of where this would be necessary…

You have set scenes that get triggered by your media player. (Lights Dim when media plays for example).
You use Alexa to call a scene (Tropical twilight as an example).
You settle down to watch something. The lights dim as per your written scene. All great up to now. Media is paused … This is where a call to return back to previous state would be required. Instead, you have to call another scene which overrides what you previously set using Alexa. You then have to use Alexa to turn Tropical Twilight back on.

Another example.

You write a trigger that if it rains, your lights flash. After flash is finished the lights do not return back to thir previous state.

I guess you get the idea. I cant help, although outside of my remit of knowledge, that this would be fairly easy to implement and can’t believe more people are not screaming out about this?

I didn’t know it was part of the api, and I’ve not really experienced any requirements for this myself (although I’m sure in the not too distant future I will be wanting it) , and I would have no idea where to start to try and help update the component but…

I can suggest a workaround. You can set an input number or variable with the brightness and colour of the affected lights before the scene, and then restore those values later.

I know it depends on how many scenes this will affect for you as to how much effort this will be, but it’s an option until a restore function is added to the component.

mf_social, great idea, however I got stuck at the part of how to set the current state of the lights as the input_number values :frowning:

Off to the top of my head thinking about your movie lights dim idea, it would be something like:

(presumes you have a scene called ‘movie_lights’ and are saving the brightness value for a light called ‘living room’ in an input_number called ‘brightness’)

You press play, this triggers an automation, which fires and runs this script…

save_light:
  alias: Save light state
  sequence:
    - service: input_number.set_value
      data_template: 
        entity_id:
          - input_number.brightness
        value: '{{states.light.living_room.attributes.brightness | float }}' 
    - service: scene.turn_on
      entity_id: scene.movie_lights

Then you press stop, which triggers an automation that fires this script:

resume_light:
  alias: Resume light state
  sequence:
    - service: light.turn_on
      data_template: 
        entity_id:
          - light.living_room
        brightness: '{{states.input_number.brightness.state | float }}' 

Obviously if you’re saving colour values too it will be more complicated, and that code will probably not work straight off as I’m typing it freehand on my phone, it’s totally off the top of my head, and I’m notoriously crap at getting templates right first time, but hopefully you get the gist.

In fairness the ‘stop’ automation probably doesn’t need to fire a separate script, you could probably put it straight into the automation.

1 Like

Thanks so much for this. I was almost there but I just had no idea how to write the current value to be held in the variable, i.e this part…

value: '{{states.light.living_room.attributes.brightness | float }}'

…which is totally new to me so I have learnt something :slight_smile:
I will let you know how it goes and if I had to tweak it any so that hopefully helps others who may read this thread

1 Like