Hey everyone,
I am trying to automate some ceiling fans that have RF remotes. I am able to work them out, but there is a lot of code duplication between the fans, so I am trying to come up with parametrized scripts to avoid the duplication.
I am able to do this just fine:
backyard_fan_power:
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_power }}"
- service: input_boolean.turn_{{ fan_operation }}
target:
entity_id: "{{ fan_state_entity_id }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_entity_id }}"
data:
value: "{{ 33 if fan_command == 'on' else 0 }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: "{{ 33 if fan_command == 'on' else 0 }}"
But this doesn’t work:
backyard_fan_set_speed:
sequence:
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_entity_id }}"
data:
value: "{{ percentage }}"
- choose:
# want to get fan to 33%
- conditions:
- condition: state
entity_id: "{{ fan_speed_entity_id }}"
state: "33.0"
sequence:
- choose:
# fan is at 66%, decrease once
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "66.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_dec }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 33
# fan is at 100%, decrease twice
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "100.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_dec }}"
num_repeats: 2
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 33
# want to get fan to 66%
- conditions:
- condition: state
entity_id: "{{ fan_speed_entity_id }}"
state: "66.0"
sequence:
- choose:
# fan is at 33%, increase once
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "33.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_inc }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 66
# fan is at 100%, decrease once
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "100.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_dec }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 66
# want to get fan to 100%
- conditions:
- condition: state
entity_id: "{{ fan_speed_entity_id }}"
state: "100.0"
sequence:
- choose:
# fan is at 33%, increase twice
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "33.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_inc }}"
num_repeats: 2
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 100
# fan is at 66%, increase once
- conditions:
- condition: state
entity_id: "{{ fan_speed_previous_entity_id }}"
state: "66.0"
sequence:
- service: remote.send_command
target:
entity_id: remote.rm4_pro
data:
command: "{{ fan_command_speed_inc }}"
- service: input_number.set_value
target:
entity_id: "{{ fan_speed_previous_entity_id }}"
data:
value: 100
default: []
The error I get is:
2023-05-31 22:20:38.124 ERROR (MainThread) [homeassistant.components.script] Script with object id 'backyard_fan_set_speed' could not be validated and has been disabled: Entity {{ fan_speed_entity_id }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['sequence'][1]['choose'][0]['conditions'][0]['entity_id']. Got '{{ fan_speed_entity_id }}'
Entity {{ fan_speed_previous_entity_id }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['sequence'][1]['choose'][0]['sequence'][0]['choose'][0]['conditions'][0]['entity_id']. Got '{{ fan_speed_previous_entity_id }}'
It feels like the script doesn’t allow the nested choose
blocks to access the variables being passed.
Anyone has any clue on how to solve this issue?
Thank you