Yet another dimmer/scene switch blueprint

Sorry I had missed your first message. The loop control is dictated by a few things

  • The script must be configured as mode: restart
  • The physical switch firmware sends KeyHeldDown event which enters the construct
  • When the automation is configured with is_loop_for_key_up_held: true, the instructions under the event repeat indefinitely until the script restarts.
    • Conventionally we anticipate that KeyReleased is that event but I suppose any event the configured switch sends would jump out of this repeat

This is actually the part that matters the most:

- repeat:
    sequence: !input 'key_up_held'
    until: '{{ not is_loop_for_key_up_held }}'

The instruction repeat is the control flow. If you’re familiar with a programming language this might read out as

do
{
  /* do events associated for the key_up_held event (as an example) */
}
while(true)

Also, you might ask why am I referring to this as do{} while(true) when the configuration expresses until: '{{ not is_loop_for_key_up_held }}'? The end-user configured setting cannot change after the script starts, so this construct implicitly anticipates that the script will restart on the next button click. That last sentence might help clear up your understanding on why this works.

Yea I get that, but where are you actually defining what is_loop_for_key_up_held is? Is that something built into HA? Are you looking for an event?

That’s the part I’m stuck on. Could you put the logic you would use for a normal automation, and not your blueprint?

This is what my automation config looks like through your blueprint. The part that I can’t understand how it is defined is this part. Where is
{{ not is_loop_for_key_up_held }}
defined? Is this something built into HA that I am unaware of, or is it defined somewhere in your blueprint that I am missing?

        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id:
                      - light.kitchen_ceiling_lights
                      - light.kitchen_sink_light
                  data:
                    brightness_step_pct: 10
              until: '{{ not is_loop_for_key_up_held }}'

Full automation:

mode: restart
max_exceeded: silent
variables:
  zwavejs_device_id: 7f552b201b789b8ca967fb519c112fa1
  is_key_up_scene_two: false
  key_up_scene_id: '{{ ( (1,2)[is_key_up_scene_two] | int ) }}'
  key_down_scene_id: '{{ ( (2,1)[is_key_up_scene_two] | int ) }}'
  is_loop_for_key_up_held: true
  is_loop_for_key_down_held: true
trigger:
  - platform: event
    event_type: zwave_js_value_notification
condition: >-
  {{ trigger.event.data.device_id == (zwavejs_device_id | string) and
  trigger.event.data.command_class == 91 }}
action:
  - variables:
      scene_id: '{{ (trigger.event.data.property_key_name | int) }}'
      key_pressed: '{{ trigger.event.data.value }}'
  - choose:
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyPressed" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id:
                - light.kitchen_ceiling_lights
                - light.kitchen_sink_light
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyPressed" }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id:
                - light.kitchen_ceiling_lights
                - light.kitchen_sink_light
      - conditions: '{{ scene_id == 3 and key_pressed == "KeyPressed" }}'
        sequence: []
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyReleased" }}'
        sequence: []
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyReleased" }}'
        sequence: []
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyHeldDown" }}'
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id:
                      - light.kitchen_ceiling_lights
                      - light.kitchen_sink_light
                  data:
                    brightness_step_pct: 10
              until: '{{ not is_loop_for_key_up_held }}'
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyHeldDown" }}'
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id:
                      - light.kitchen_ceiling_lights
                      - light.kitchen_sink_light
                  data:
                    brightness_step_pct: -10
              until: '{{ not is_loop_for_key_down_held }}'
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyPressed2x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyPressed2x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyPressed3x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyPressed3x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyPressed4x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyPressed4x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_up_scene_id and key_pressed == "KeyPressed5x" }}'
        sequence: []
      - conditions: '{{ scene_id == key_down_scene_id and key_pressed == "KeyPressed5x" }}'
        sequence: []
id: '1637374713801'
alias: '👆🏻 Single/Double Tap: Kitchen Ceiling Lights'
description: ''

ping @moshess

So the variable is_loop_for_key_up_held is a user-config variable from the blueprint. If you want to use the concept here, then replace it with any boolean condition; so something like until: false might work. You may want to review the Script Syntax - Home Assistant wiki page to consider other options for your use case. I think while: {{ true }} would probably be okay. Remember, be sure to use the script restart, otherwise you might be introducing a never-ending loop.

@moshess OK there seems to be some misunderstanding going on here. I understand the concept of a loop, I understand how the script syntax goes, but I don’t know what you are looking for to tell when the paddle is let go. You cannot use an event as the “until” portion of the repeat, and I don’t know what logic you were using to determine that. I hope this makes sense.

choose:
  - conditions:
      - condition: trigger
        id: KeyHeldDown
    sequence:
      - repeat:
          until:
            - condition: I DONT KNOW WHAT TO PUT HERE
          sequence:
              - service: light.turn_on
                target:
                  entity_id:
                    - light.kitchen_ceiling_lights
                    - light.kitchen_sink_light
                data:
                  brightness_step_pct: -10
default: []

Ping @moshess

Pinging @moshess

@broyuken1 sorry for the late response. I think the condition might be asserted as false.

choose:
  - conditions:
      - condition: trigger
        id: KeyHeldDown
    sequence:
      - repeat:
          until:
            - condition: false

On the surface this is a bad idea because is a never ending loop but that matches how the blueprint is configured. What makes it work, is by using the the script configuration mode: restart

script:
  foo:
    mode: restart

@moshess Hey there, could you give an example of how you implement dimming with this blueprint? On/Off is pretty straight forward to me but I don’t understand how to dim. I’m using an older Homeseer HS-WD100 dimmer that is not a scene controller and Hue bulbs. Thanks