Hi all,
I used the following automation to pass a variable to a script:
- alias: 'ESP32 MQTT holding button 0'
trigger:
platform: mqtt
topic: esp32/button_hold_0
payload: "on"
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.button_hold_0_toggle
state: 'on'
sequence:
service: script.turn_on
target:
entity_id: script.dim_lounge_left
data:
variables:
upOrDown: "1"
- conditions:
- condition: state
entity_id: input_boolean.button_hold_0_toggle
state: 'off'
sequence:
service: script.turn_on
target:
entity_id: script.dim_lounge_left
data:
variables:
upOrDown: "-1"
It appears to work correctly and passed the value of 1.
The script is as follows:
dim_lounge_left:
fields:
upOrDown:
description: "Dim lights up or down"
sequence:
- service: light.turn_on
data:
entity_id: light.lounge_left
brightness: "{{ (((state_attr('light.lounge_left', 'brightness'))|int) + (upOrDown|int)) }}"
- service: system_log.write
data_template:
level: debug
logger: my_debug
message: "{{ (((state_attr('light.lounge_left', 'brightness'))|int) + (upOrDown|int)) }}"
- service: script.turn_off
target:
entity_id: script.dim_lounge_left_runagain
- service: script.turn_on
target:
entity_id: script.dim_lounge_left_runagain
data:
variables:
upOrDown: '{{ upOrDown }}'
dim_lounge_left_runagain:
fields:
upOrDown:
description: "Dim lights up or down"
sequence:
- service: script.turn_off
target:
entity_id: script.dim_lounge_left
- service: script.turn_on
target:
entity_id: script.dim_lounge_left
data:
variables:
upOrDown: '{{ upOrDown }}'
Now, the problem is that the script is not actually adding 1 to the brightness. If I replace +(upOrDown|int) with +1 it works. I used the debug log to check that the upOrDown was actually 1, and it showed up as 1 in my log. Anyone know why this isn’t working?