FatMitch
(Mitch)
February 4, 2021, 8:50pm
1
In my script I want to set the variables that I pass to the next script based on the outside temperature but I’m doing something wrong because I’m getting an error of weather undefined. I know that weather.wingate.temperature is a thing just not sure how to reference it and set the logic correctly in the if then else statement. here’s the script:
alias: Humidifier Control Logic
sequence:
- service: script.turn_on
entity_id: script.humcontrolstep2
data:
variables:
maxhumidity: >
{% if weather.wingate.temperature < 0 %} 30 {% elif weather.wingate.temperature < 10 %} 35 {% elif weather.wingate.temperature < 20 %} 40 {% elif weather.wingate.temperature < 40 %} 45 {% else %} 65 {% endif %}
minhumidity: >
{% if weather.wingate.temperature < 0 %} 20 {% elif weather.wingate.temperature < 10 %} 25 {% elif weather.wingate.temperature < 20 %} 30 {% elif weather.wingate.temperature < 40 %} 35 {% else %} 50 {% endif %}
mode: single
123
(Taras)
February 4, 2021, 9:22pm
2
Try this:
alias: Humidifier Control Logic
sequence:
- variables:
th: >
{% set t = state_attr('weather.wingate', 'temperature') | float %}
{% if t < 0 %} [30, 20]
{% elif t < 10 %} [35, 25]
{% elif t < 20 %} [40, 30]
{% elif t < 40 %} [45, 35]
{% else %} [65, 50]
{% endif %}
- service: script.turn_on
entity_id: script.humcontrolstep2
data:
variables:
maxhumidity: '{{ th[0] }}'
minhumidity: '{{ th[1] }}'
mode: single
FatMitch
(Mitch)
February 5, 2021, 1:35am
3
Now the next step is giving me an error of expected float for dictionary where I reference the variable in the next script. The code looks something like this
humcontrolstep2:
alias: HumControlStep2
fields:
maxhumidity:
description: Maximum humidity level that will be tolerated in any active zone
example: 65
minhumidity:
description: Minimum humidity level that will trigger humidifier in any active
zone
example: 55
sequence:
- choose:
- conditions:
- condition: or
conditions:
- condition: and
conditions:
- condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
domain: climate
entity_id: climate.downstairs
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
entity_id: sensor.downstairs_humidity
domain: sensor
above: '{{ maxhumidity | float }}'
below: 150
123
(Taras)
February 5, 2021, 4:15am
4
Is that all of the script or just a portion of it?
FatMitch
(Mitch)
February 5, 2021, 2:32pm
5
Here’s the whole thing:
humcontrolstep2:
alias: HumControlStep2
fields:
maxhumidity:
description: Maximum humidity level that will be tolerated in any active zone
example: 65
minhumidity:
description: Minimum humidity level that will trigger humidifier in any active
zone
example: 55
sequence:
- choose:
- conditions:
- condition: or
conditions:
- condition: and
conditions:
- condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
domain: climate
entity_id: climate.downstairs
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
entity_id: sensor.downstairs_humidity
domain: sensor
above: '{{ maxhumidity | float }}'
below: 150
- condition: and
conditions:
- condition: device
device_id: 4348095d4f3d75c83b9a7676850fa6ba
domain: climate
entity_id: climate.living_room
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 4348095d4f3d75c83b9a7676850fa6ba
entity_id: sensor.living_room_humidity
domain: sensor
above: '{{ maxhumidity | float }}'
below: 150
- condition: and
conditions:
- condition: device
device_id: 4171867aea6553495a18c621f27bb894
domain: climate
entity_id: climate.master_bedroom
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 4171867aea6553495a18c621f27bb894
entity_id: sensor.master_bedroom_humidity
domain: sensor
above: '{{ maxhumidity | float }}'
below: 150
sequence:
- type: turn_off
device_id: 1f45c77b73dcbaeb59895017affe7225
entity_id: switch.humidifier_control
domain: switch
- conditions:
- condition: or
conditions:
- condition: and
conditions:
- condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
domain: climate
entity_id: climate.downstairs
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 798e40f56aa4cfc8560fb105935b7aef
entity_id: sensor.downstairs_humidity
domain: sensor
below: '{{ minhumidity | float }}'
- condition: and
conditions:
- condition: device
device_id: 4348095d4f3d75c83b9a7676850fa6ba
domain: climate
entity_id: climate.living_room
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 4348095d4f3d75c83b9a7676850fa6ba
entity_id: sensor.living_room_humidity
domain: sensor
below: '{{ minhumidity | float }}'
- condition: and
conditions:
- condition: device
device_id: 4171867aea6553495a18c621f27bb894
domain: climate
entity_id: climate.master_bedroom
type: is_hvac_mode
hvac_mode: heat
- type: is_humidity
condition: device
device_id: 4171867aea6553495a18c621f27bb894
entity_id: sensor.master_bedroom_humidity
domain: sensor
below: '{{ minhumidity | float }}'
sequence:
- type: turn_on
device_id: 1f45c77b73dcbaeb59895017affe7225
entity_id: switch.humidifier_control
domain: switch
default:
- type: turn_off
device_id: 1f45c77b73dcbaeb59895017affe7225
entity_id: switch.humidifier_control
domain: switch
mode: single
123
(Taras)
February 5, 2021, 3:32pm
6
I noticed you already have a separate thread to discuss this script’s problem so I posted my response there:
I have streamlined script.humcontrolstep2 so that it no longer relies on Device Conditions.
You will have to check and confirm the condition logic is correct because it was a bit challenging to decipher it from the original script.
humcontrolstep2:
alias: HumControlStep2
fields:
maxhumidity:
description: Maximum humidity level that will be tolerated in any active zone
example: 65
minhumidity:
description: Minimum humidity level that will trigger humidifier in any …