Lights to turn on with former state

I have bunch of lights in the livingroom so I divided them into three groups : wall, tv and back. I have created an automation with my hue sensor to activate livingroom lights with motion.

alias: Living Room On
description: ''
  - type: motion
    platform: device
    device_id: 9e448e4259dd27b5bec1d8081b40aded
    entity_id: binary_sensor.hue_motion_sensor_3_motion_2
    domain: binary_sensor
condition: []
  - service: script.living_room_wall_on
  - service: script.living_room_duvar_on
  - service: script.1637314014716
mode: single

My wall script is as follows :

  - service: light.turn_on
        - light.hue_play_sol
        - light.duvar_sag
        - light.tv_led_light
mode: single
alias: Living Room Wall On

I also have several scenes in the livingroom which I activate through Alexa.

The problem is although my automation is just a simple “Light Turn On” command but the lights does not open with their last closed state. Instead for example the wall light opens with a very different colour.

Everything goes fine for a few days but later on, the above problem occurs. Even all the lights were turned off when they were in “Movie Mode” the come up very bright and different color with this automation.

Anyone have any idea ?

Edit: I am controlling the lights in the livingroom with Alexa routines but are using automations in Home Assistant

Can you create a home assistant scene for the devices you want before changing them, then set that as active afterwards?

I actually want the lights to be turned on with their last state. Is that possible ?

You can create a scene in HA whenever you want, so if HA is turning them off, create a scene first and stash that, then later invoke it. If you’re turning them off outside of HA, you might be able to just periodically create that scene (or multiple rule driven scenes) so that you know how the lights were when they were on.

There may be a better way, but I would think you could just create as many scenes as you need based upon which lights are on, then call those scenes to restore the last state.

Another way might be to use an automation that periodically just writes down the brightness/rgb values for each light you want to target, if its on. Then when you call your wake up, you can feed in each of the most recently stashed values.

A few things to think on. As I say, there’s probably a better way.

I’m thinking this is a hardware issue.

What sort of lights are they?

e.g. My Lifx lights always turn on with the previous state.

I have been able to fix the problem. It seems that the problem occured from the official Hue app. The misbehaving wall lights were Philips lights and because I was using the official hue integration on HA, the automation I mentioned above with hue sensors were taking orders from the hue app. Hue Motion sensors have different settings with the “lights on” command for different time of the day. When I checked the app the living room sensors night behaviour (between 23:00-08:00) was to set to “bright” when motion is detected. So no matter what the last state was, every single time the lights was turning on with that bright setting. There is also an option named “Do Nothing” and when I checked that the lights now turning on with the last state it was closed.