YAML help to restore light/switch conditions to earlier state

Hi All,

Need some help here (got tip to use trigger.from_state.state but dont know how to use it)

Scenario:
When my Alarmpanel triggers alarm I put all switches to on and all lights on with brightness 255 (removed som lines for all switches and lights to simplify):

- id: Alarm Panel Alarm
  alias: Alarm Panel Alarm
  trigger:
  - platform: state
    entity_id: binary_sensor.alarm_panel_alarm
    from: 'off'
    to: 'on'
  action:
  - service: light.turn_on
    entity_id:
    - light.driveway
    data:
      brightness: 255
  - service: switch.turn_on
    entity_id:
    - switch.bed_room_window

The Question is when:

- id: Alarm Panel Restored
  alias: Alarm Panel Restored
  trigger:
  - platform: state
    entity_id: binary_sensor.alarm_panel_alarm
    from: 'on'
    to: 'off'

How can I get all lights and switches back to the state they were before the alarm (could have been anything depending on the time of the day)?
At the moment I just solved it to get switches off and lights to 128 brightness

Thanks,
Ase

https://www.home-assistant.io/integrations/scene/#creating-scenes-on-the-fly

1 Like

You can use Scenes for this if it’s a static brightness on a set number of lights. Otherwise you might have to use helpers to store the values or use a template entity with attributes that lay out the values and devices you want to modify, then tap into those attributes to do what you want.

This seems promising, will test!

Thanks,
Ase

1 Like

Yeah creating scenes on-the-fly are awesome.

Store your states in a scene, do your thing that messes with the states, restore your saved scene.

1 Like

Worked Great!
Thanks a lot!

1 Like

When added all my entities (21 pieces), this does not work that great anymore,
After some testing I found out that Light Groups seems to trigger but cannot restore to previous state.
The lights in the group seems to go into all kind of different states.

Thanks,
Ase

You have to break out the light groups into individual lights when creating scenes on the fly. Otherwise the light group will treat all grouped lights the same. I.e. each light will be set to what the group is set to.

@petro, that is what i want to all go back to what all was before. Invidual lights in the group seems to go into all different states an brightnesses. Will try to ignore the groups and go per device instead.

Thanks,
Ase

As I see it, scenes on-the-fly cannot handle light groups, only invidual devices.
Comments on this please?

Thanks,
Ase

Yes, that’s what I said… It can handle light groups but it’s not going to restore the individual lights inside it. It will restore all individual lights to what the group had.

e.g.

Your light group is on. Lights A, B and C make up the group. THe light group is on because A is on, B and C are off.

If you restore that light group state, A, B and C will turn on because it’s restoring the “on” state of the group.

Yes, that what I woudl like to have, but it does not work like that for me.

Example:
Have a group “Living Room Windows” consiting of 2 lights grouped into a group entity.
On “trigger” they both go up to 255 brghtness, but on the restore one goes back to the old value the other can go to something else, 75% often as it seems.
Both started at the same brightness before alarm

//Ase

Then it seems that would be an issue with the hardware itself. Are you altering the transition time? Do the lights have different transition times?

Now this is a question I cannot answer.
Using a HA Yellow and using IKEA lights, nothing special.
//Ase

When I say hardware, I’m talking about your lights, not HA.

Your question was answered in the same answer above about the hardware.
I will go with the theory that “scenes-on-the-fly” cannot use light groups and try to map it by device instead.

I know that but you didn’t give any detail.

Are they the same lights? I.e. Brand / Firmware / Protocol?

All IKEA, All on latest firmware, all on Zigbee