Save and restore Functionality (state of lights)

I would find it useful to be able to save the state of the lights, do something (like FLASH/Blink/Party mode) them and then restore them to the previous state. Similar to the functionality of the scene but more isolated so I could use it in scripts or automations. Not sure if this is a niche thing for me or if others would find it useful.

I am specifically thinking about it with the addition of IFTTT support. I want to use triggers on IFTTT and lights as the notifier on HA but need to be able to somehow set them BACK to whatever they were before sending the flash alert.

Example: Flash a light (or THE ENTIRE HOUSE) when
any IFTTT notification comes in (Mail, Tweet, Meeting, etc…)
Eventually when a VOIP call comes in.
Alarm/timer ends on Amazon Echo
z-Wave Doorbell rings, Mailbox Opens, Pool gate opens.

All of these things require a way to save the current state and then restore them. I tried to use scene but the flash:long service can’t be included in the scene. (I guess it’s not a state).

So the easy way might be to just add flash to scenes but a more broader solution might be to create a separate save/restore function.

This is a request that was originally posted on Github #408

Could the new SceneGen code be used/ported to help accomplish this?

https://github.com/acockburn/scenegen by @acockburn

This is a great idea. There’s a lot of use cases for a save/restore feature within scripts.

Hi guys,

I’m have been trying to solve a similar problem. For the Hue lights specifically, the problem is the implementation of the alert or flash function in HA is kinda broken IMO.

Hue lights natively support a flash function that can be used without effecting the current colour settings but the poor implementation of this function in HA is the main issue.

E.g. The flash function in HA can on only be called with a turn_on command. So if a light was off and you issued a flash command to it, it will stay on after flashing unless you issue a second command to turn it off.

I have proposed a solution here https://community.home-assistant.io/t/new-service-lights-flash/ to add an additional HA service to properly support the native alert/flash function of the Hue API (and other lights too if there is native support for such a function) called light.flash, so turning a light in isn’t the only way to issue the flash command to a light. Allowing you to flash any light, regardless of its state and have it return to its previous state before flashing.

If you think this is a good idea and would go some way to solving your problem also, please vote up my post. Cheers!

2 Likes

Gents,

I would like to comment a moment here, if you would be so kind to allow. This comment is specifically on Hue lights only. I have embarked on quite an adventure for some time to find something that would solve this problem. The cause was different, but the effect the same.

Before I continue, one thing I can’t stress enough is the fact that I’m not a programmer. It have little formal training in it, and everything I have learned has been on my own. A year ago, I only knew VBA as excel is tool of choice for my trade.

The source of my problem was the transition time. Whenever a light is turned back on after using transition time to turn it off, the resulting brightness is 1. Storing the state of the light prior to the off command was the solution to this problem, and off I went on my odyssey.

The best solution I have found is to include the a state with every on command. And the method I think works well, is using the scenes functionality of the Hue System built into the hub itself. Hue scene recall commands are sent to the hub, and are executed on group 0, along with any group the sender specifies. So, I have created not only groups, but individual groups in the hub for every light. I turn on individual lights using the group command and a scene id.

For example, I may have a default scene, which has a state for every light in my house. I also have a group defined for each individual light. When I want to turn on a light, I send the sceneId and the groupId to turn it on.

This is the best I have come up with, and thought I would share my trials and tribulations.

This journey also has brought me to trying HA, which I started using last week and plan on using for the state machine and automation engine, as I quite like the UI I have built (another shortcoming of the opensource smart-home solutions I have tried, but I digress). It seems quite promising to save state, and but I’m still learning the ecosystem and hope this may help.

Regards,
ap

FYI: HASS v0.28 brings with it an update that allows the functionality I was requesting but without adding another service to do it. Instead its using the existing lights service. which partially addresses the topic of this thread also.:slight_smile:

1 Like

What exactly are you referring to here?

1 Like

See this PR. https://github.com/home-assistant/home-assistant/pull/3147

In my case, I do things like brighten the front porch lights on motion, then return them to the correct state after 5-10 min. So I’d like to record that info for longer than the duration of a flash/alert.

It’s possible with the Rest API to add attributes to an entity. I think we’d be able to do this (plus a lot of other things) if there was a service to let us create, set, and retrieve attributes from within HA.

Almost like a Current State Attribute, Last State Attribute and a Revert action.

Something like

- service: homeassistant.set_attribute
  entity_id: light.front_porch
  value: 'x'

You could retrieve it with the existing data template functions.

1 Like

Hmm … Set and Get… is it possible to use input.boolean and templates to achieve something similar?

You can’t use input_boolean to store a value. You could use it to store on/off, but not brightness, color, or anything like that.

1 Like

I have a similar need - i want to create a “scene” called workout that turns off the heater (z-wave thermostat valve) in the room, turns on the light and tv etc. and it turns off in for example 1 hour. The problem i’m facing is the heater - i want to set it to the previous value - my workaround is to save the previous value to an input slider and after the 1h set the thermostat back to the temperature set in the slider.

It might be problematic when an automation rule kicks in that 1 hour period - not sure how to tackle that - probably need a schedule module that would just return the temp for the specific time/day of week.

Any updates here, this would be a great feature with many use cases.

Same as last question, any updates?
This would be a really awsome and useful feature!

My frustration is not being able to save states of lights or other devices on reboot.

Because I have LimitlessLED (which is very limited) I have automations changing the light color temperature throughout the day and night whether or not the lights are on. In order to do this without turning the lights on every time the color temp changes throughout the day I save it to an input_number and then whenever a light is turned on it triggers another automation to update the color to whatever is saved in the input_number. However, none of these values survive a restart.

For the OP if you were to use one or more input_number to store values of given lights you could create a flash or alert with the lights and then return to the stored values in said input_number.

Or we could just add save and restore functionality :wink:

1 Like

Not sure if the values for input_number are saved, but be sure you’re not setting an initial state. If memory serves, that’ll supersede the saved data.

I believe the new SQL Sensor introduced in 0.63 is the answer we’ve been looking for. I’d be curious to hear how people use this!