JeffX
(Jeff)
September 4, 2023, 12:31pm
1
Hi,
Im trying to use one script (toggle) many climate devices.
For example tap action:
tap_action:
action: call-service
service: script.toggle_heater
data:
tentity: climate.f1a1
and script:
toggle_heater:
alias: toggle_heater
sequence:
- if:
- condition: and
conditions:
- condition: template
value_template: >-
{% set device = '{{ tentity }}' %}
{{ is_state('climate.f1a1', 'heat') }}
then:
- service: climate.turn_off
data:
entity_id: '{{ tentity }}'
But without success (else condition missing but they are similar)
I need help what I’m doing wrong ?
Is it possible to send parameter in this way?
Thank you in advance
123
(Taras)
September 4, 2023, 12:40pm
2
toggle_heater:
alias: toggle_heater
sequence:
- condition: template
value_template: "{{ is_state(tentity, 'heat') }}"
- service: climate.turn_off
target:
entity_id: '{{ tentity }}'
JeffX
(Jeff)
September 4, 2023, 1:13pm
3
Hi,
Cannot determine status in if condition.
Current status from developer tools for this device is “heat”
But result in script is false:
Result:
result: false
condition: template
value_template: '{{ is_state(tentity, ''heat'') }}'
Still not working.
Thank you for suggestion
123
(Taras)
September 4, 2023, 1:31pm
4
If the script didn’t receive a value of climate.f1a1
in the tentity
variable then there may be an issue with how tap_action
is configured.
Try this version:
tap_action:
action: call-service
service: script.toggle_heater
service_data:
tentity: 'climate.f1a1'
toggle_heater:
alias: toggle_heater
sequence:
- variables:
t: "{{ tentity | default('climate.f1a1', true) }}"
- condition: template
value_template: "{{ is_state(t, 'heat') }}"
- service: climate.turn_off
target:
entity_id: '{{ t }}'
JeffX
(Jeff)
September 4, 2023, 1:44pm
5
123:
toggle_heater:
alias: toggle_heater
sequence:
- variables:
t: "{{ tentity | default('climate.f1a1', true) }}"
- condition: template
value_template: "{{ is_state(t, 'heat') }}"
- service: climate.turn_off
target:
entity_id: '{{ t }}'
When I try to toggle f1a2 device
tap_action:
action: call-service
service: script.toggle_heater
data:
tentity: climate.f1a2
double_tap_action:
action: more-info
Device f1a1 going to turn off.
123
(Taras)
September 4, 2023, 1:55pm
6
I designed the script to use climate.f1a1
by default if it doesn’t receive a value for tentity
.
The results of your test prove that the script is not receiving a value for tentity
.
I suggest you try the version I had suggested which uses service_data
instead of data
.
tap_action:
action: call-service
service: script.toggle_heater
service_data:
tentity: climate.f1a2
double_tap_action:
action: more-info
JeffX
(Jeff)
September 4, 2023, 2:05pm
7
123:
service_data
Yeeee now working as expected.
Thank you
Now second question how to make else ?
123
(Taras)
September 4, 2023, 2:12pm
8
JeffX:
how to make else ?
You will need to provide more details about what you want to do because “make else” isn’t sufficiently clear.
JeffX
(Jeff)
September 4, 2023, 2:17pm
9
toggle_heater:
alias: toggle_heater
sequence:
variables:
t: "{{ tentity | default('climate.f1a1', true) }}"
if:
- condition: template
value_template: "{{ is_state(t, 'heat') }}"
- service: climate.turn_off
target:
entity_id: '{{ t }}'
else:
- service: climate.set_temperature
data:
temperature: input_number.default_climate_themperature
hvac_mode: heat
target:
entity_id: '{{ t }}'
Something similar like this but this not working
123
(Taras)
September 4, 2023, 2:21pm
10
toggle_heater:
alias: toggle_heater
sequence:
- variables:
t: "{{ tentity | default('climate.f1a1', true) }}"
- if:
- condition: template
value_template: "{{ is_state(t, 'heat') }}"
then:
- service: climate.turn_off
target:
entity_id: '{{ t }}'
else:
- service: climate.set_temperature
data:
temperature: "{{ states('input_number.default_climate_themperature') }}"
hvac_mode: heat
target:
entity_id: '{{ t }}'
EDIT
Correction. Overlooked to include hyphens.
JeffX
(Jeff)
September 4, 2023, 2:29pm
11
For something reason script is not loaded:
Script is unavailable
Actions: extra keys not allowed @ data[0][‘if’]
JeffX
(Jeff)
September 4, 2023, 2:35pm
12
toggle_heater:
alias: toggle_heater
sequence:
- variables:
t: "{{ tentity | default('climate.f1a1', true) }}"
- if:
- condition: template
value_template: "{{ is_state(t, 'heat') }}"
then:
- service: climate.turn_off
target:
entity_id: '{{ t }}'
else:
- service: climate.set_temperature
data:
temperature: "{{ states('input_number.default_climate_themperature') }}"
hvac_mode: heat
target:
entity_id: '{{ t }}'
This work as expected
Thank you very much " 123 Taras "
123
(Taras)
September 4, 2023, 2:35pm
13
That’s due to my mistake. I have corrected the example posted above.
123
(Taras)
September 4, 2023, 2:37pm
14
JeffX:
Thank you very much
You’re welcome!
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
For more information about the Solution tag, refer to guideline 21 in the FAQ .