Slider automation fix

The following version is designed to handled a payload containing any number of keys. Whether the payload contains one key or many keys, only the four desired keys are processed:
['brightness', 'stay_time', 'up_time', 'down_time']

- alias: Slider value
  id: '1634116488690'
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_number.vestibule_light_brightness
    - input_number.vestibule_light_stay_time
    - input_number.vestibule_light_up_time
    - input_number.vestibule_light_down_time
  - platform: mqtt
    topic: /devices/state/iot0
    value_template: '{{ value_json }}'
  condition: []
  action:
  - choose:
    - conditions: "{{ trigger.platform == 'state' }}"
      sequence:
      - service: mqtt.publish
        data:
          topic: /devices/cmd/iot0
          payload: '{"{{ trigger.to_state.object_id[16:]  }}": {{states(trigger.entity_id) | int(0)}} }'
    default:
    - variables:
        valid_keys: ['brightness', 'stay_time', 'up_time', 'down_time']
        all_keys: '{{ trigger.payload_json.keys() | list }}'
    - repeat:
        count: '{{ all_keys | count }}'
        sequence:
        - condition: template
          value_template: '{{ all_keys[repeat.index-1] in valid_keys }}'
        - variables:
            property: '{{ all_keys[repeat.index-1] }}'
            entity: 'input_number.vestibule_light_{{ property }}'
            val: '{{ trigger.payload_json[property] | int(0) }}'
        - condition: template
          value_template: '{{ val != states(entity) | int(0) }}'
        - service: input_number.set_value
          target:
            entity_id: '{{ entity }}'
          data:
            value: '{{ val }}'
  mode: queued
  max: 10

Try it out and let me know if it works and/or if it needs additional improvements.

1 Like

It works. Funny, but i tried to do something similar and it’s partially works :-/

Thank you very much.