Blueprint: Random Name for scene

I want to make a blueprint for an automation that reduces the temperature of HVAC when I open a window or door and return to temperature I set before.

To do so. I want to save the actual temperature in a scene.

As there many rooms in my house I can’t just use one fixed name for that scene otherwise it will be overwritten.

That’s why want to random name for that scene which should be deleted when the automation is finished.

Can someone please help me how to do that?

action:
  sequence:
    - action: scene.create
      data:
        scene_id: scene_name
        snapshot_entities:
          - !input climate_target
    - action: climate.set_temperature
      data:
        temperature: 5
      target:
        entity_id: !input climate_target
   - wait_for_trigger:
        - trigger: state
          entity_id: !input window_entity
          to: "off"
      continue_on_timeout: false
   - delay: !input minimum_close_time
   - action: scene.turn_on
      target:
        entity_id: scene.{{scene_name}}
    - action: scene.delete
      target:
        entity_id: scene.{{scene_name}}

Hi Peter, do you mind sharing the reason for creating a blueprint and not just an automation?
If it’s only for yourself, you can create an automation, duplicate, edit and rename it.

That’s the simple way but somehow, you could use the different entities in a template to create your scenes as well.

If its working I will share it with my friends and maybe here.

I need this in ten rooms for me only. And other seven rooms for my parents

Owkay… can’t help you with the BP since never looked at it how to create them.

Since your automations have to be aware of the room and the door/window sensor in that area, you could use that as a variable somehow.

Another idea that comes to my mind - don’t know if this is the ‘right/best’ way - is to create 1 automation with different triggers for every room, assign trigger_id’s and use the choose action with the different triggers as condition.

Found a solution:

variables:
  open_action: !input open_action
  close_action: !input close_action
  random_number: "{{range(1, 1000) | random}}"
  random_scene: "saved_temperature{{random_number}}"
mode: single
trigger:
  - trigger: state
    entity_id: !input window_entity
    to: "on"
    for: !input minimum_open_time
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: !input climate_target
        state: "off"
action:
  sequence:
    - action: scene.create
      data:
        scene_id: "{{random_scene}}"
        snapshot_entities:
          - !input climate_target
    - action: climate.set_temperature
      data:
        temperature: 5
      target:
        entity_id: !input climate_target
    - choose:
        - conditions: "{{ open_action is defined and open_action|length > 0 }}"
          sequence: !input open_action
    - wait_for_trigger:
        - trigger: state
          entity_id: !input window_entity
          to: "off"
      continue_on_timeout: false
    - delay: !input minimum_close_time
    - choose:
        - conditions: "{{ close_action is defined and close_action|length > 0 }}"
          sequence: !input close_action
    - action: scene.turn_on
      target:
        entity_id: "scene.{{random_scene}}"
    - action: scene.delete
      target:
        entity_id: "scene.{{random_scene}}"

Hello Peter,

1 Like

Thanks.

With that I don’t need a random number.

So I will rewrite it using this as an number behind the scene

this.context.id

Tried it but it doesn’t work. Going back to random number

Push it to lower case, as it says in the post…
The ID is lower_case_chase nomenclature.