My code got a little more complex, but Iām still not a single step further.
Better said, in case I execute the script and the light has been switched on before, it works nicely, although the logs are not confirming that.
On the other hand, if the light is off before, it switches on, turns from blue to red and returns to off, but the color remains red.
light1_flash_red:
alias: flash red
mode: single
sequence:
- service: scene.create
data:
scene_id: before
snapshot_entities:
- light.light_bulb
- repeat:
while:
- condition: template
value_template: "{{ repeat.index <= 6 }}"
sequence:
- service: light.toggle
data_template:
entity_id: light.light_bulb
color_name: red
- service: notify.tplogger
data:
message: In loop {{state_attr('light.light_bulb','color')}}
- delay: 1
- service: notify.tplogger
data:
message: After loop {{state_attr('light.light_bulb','color')}}
- service: script.turn_on
entity_id: script.restore_my_scene
# - service: scene.turn_on
# target:
# entity_id: scene.before
restore_my_scene:
alias: Restore state
mode: single
sequence:
- service: notify.tplogger
data:
message: Before restore {{state_attr('light.light_bulb','color')}}
- service: scene.turn_on
target:
entity_id: scene.before
- service: notify.tplogger
data:
message: After restore {{state_attr('light.light_bulb','color')}}
If I execute the script having the light on and the chosen color is blue, the following lines are logged:
In loop {'x': 0.137, 'y': 0.065}
In loop {'x': 0.137, 'y': 0.065}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
After loop {'x': 0.7006, 'y': 0.2993}
Before restore {'x': 0.7006, 'y': 0.2993}
After restore {'x': 0.7006, 'y': 0.2993}
I dont unterstand, why in the second line, it is still blue and why it has not been restored in the last line, although the physical light shows me otherwise.
If the script is executed starting having the light off, the following is logged:
In loop {'x': 0.137, 'y': 0.065}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
In loop {'x': 0.7006, 'y': 0.2993}
After loop {'x': 0.7006, 'y': 0.2993}
Before restore {'x': 0.7006, 'y': 0.2993}
After restore {'x': 0.7006, 'y': 0.2993}
Again the second line is wrong and it does not switch back to blue in the last line, but in this case, also the light stays red.
Any ideas? This is now another light bulb, just to rule out that the device might be the one to be blamed. I might remove all that fancy scene stuff and write a lot of manual steps, but this would be like quitting.