#Needing help with transient (on-the-fly) scene creation and testing

1 messages · Page 1 of 1 (latest)

cursive tusk
#

Using transient scenes in automations - help
I have a problem with setting up and using transient scene generation in automations/scripts.
Use Case:
I need to know the condition (on/off, brightness etc) of a set of lights saved after an event and used on another event. In the example the light status is saved as a on the fly scene "lights_status" when motion no longer detected. When motion is detected I want to activate the scene IF the scene was previously created OTHERWISE use a default set of values.
However the UI editor will not let me save the automation (attached) because the scene is not currently in the dictionary. How do I get around this other than (possibly) saving the automation as a package outside of the default automations.yaml file.
The test works and says the scene is not defined (ie returns false), as I would expect, and I believe with a valid scene I would get a true.
NB: I know someone is going to point out the non-preferred use of the states.scene.lights_status.state rather than states("scene.light_status") construct but see discussion in
(https://community.home-assistant.io/t/check-if-scene-created-on-the-fly-is-created-before-activating-it/521561/2?fbclid=IwY2xjawE4wQVleHRuA2FlbQIxMAABHZcynnUhBhhnwgZLqBJUzJLVbVhzgf5dnaGEVYNpKjmdqQWgKUvP4HkTsQ_aem_TPQrE6UgsscDozaUGbGvsQ) (edited)

#

Now the automation# Produces following error message

Message malformed: not a valid value for dictionary value @ data['action'][0]['then'][0]['then'][0]['target']['entity_id']description:

#line causing error is template

{{ states.scene.lights_status.state is defined }}

Sets up transient scene snapshot for later use
mode: single
trigger:

  • type: motion
    platform: device
    device_id: 80f6b8d85286d76260ea6c90729faf37
    entity_id: 87020bc830d28c95b3e855ac631aa229
    domain: binary_sensor
    id: motion detected
  • type: no_motion
    platform: device
    device_id: 80f6b8d85286d76260ea6c90729faf37
    entity_id: 87020bc830d28c95b3e855ac631aa229
    domain: binary_sensor
    id: no motion
    condition: []
    action:
  • alias: Choose between motion or no motion
    if:
    • condition: trigger
      id:
      • motion detected
        then:
    • if:
      • condition: template
        value_template: "{{ states.scene.lights_status.state is defined }}"
        then:
      • action: scene.turn_on
        metadata: {}
        target:
        entity_id: lights_status
        else:
      • action: light.turn_on
        metadata: {}
        data:
        brightness_pct: 100
        target:
        device_id: d33f5d86ecb82d419cf0601be01729b8
        alias: Check if snapshot exists else just use 100%
        else:
    • action: scene.create
      metadata: {}
      data:
      scene_id: lights_status
      snapshot_entities:
      - light.lounge_lights
    • action: light.turn_off
      metadata: {}
      data: {}
      target:
      device_id: d33f5d86ecb82d419cf0601be01729b8
      alias: Example transient scene
orchid anchor
#

It's pretty hard to tell with no formatting

cursive tusk
#

not certain what you mean. - as far as I can see the automation exanple is formatted with proper indents, the minuses seem to have been converted to degree signs

#

the real problem is how I get around the UI editor refusing to save.

woven capeBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.