Oh, lucky me, I did ask before messing it up…
Well, my automation is managing the roof-window-shutters. This morning, they should have closed, but they didn’t. I tried to have a look at the trace, but I could not figure out, why it didn’t work in the morning. In the afternoon, it was working fine.
4 guesses:
- my wife worked against the automation
- my kids played with the shutters
- one of the input values did not provide a number, but a string
- any combination of the three above
Do you mind having a short look at my configuration and checking, if my error handling - in case there is a string instead of a number - should work?
input sensor 1: UV-index by api
input sensor 2: indoor temperatur by mqtt-sensor
mqtt:
sensor:
- name: "Dachzimmer Temperatur"
unique_id: "mqtt.Dachzimmer.temp"
state_topic: "tele/D1mini/Dachzimmer/SENSOR"
device_class: "temperature"
unit_of_measurement: "°C"
value_template: "{{ value_json.DHT11.Temperature | float(none) }}"
state_class: "measurement"
(this is in a splitted config-file mqtt.yaml - so never mind the indentation)
Automation:
alias: Dach Rollo Management v4
description: |-
Based on UV-index, window shutters are opened/closed in 4 steps.
no number -> stop
0 - 1.0 -> fully open
1.0 - 1.5 -> 1/3-closed
1.5 - 2.0 -> 50%-closed
2.0 - 2.5 -> 2/3-closed
2.5+ -> 100%-closed
trigger:
- platform: state
entity_id:
- sensor.openweathermap_uv_index
for:
hours: 0
minutes: 0
seconds: 0
- platform: numeric_state
entity_id: sensor.dachzimmer_temperatur
for:
hours: 0
minutes: 5
seconds: 0
above: '22.5'
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: '{{ not is_number(states(''sensor.openweathermap_uv_index'')) }}'
sequence:
- stop: UV-Index liefert keine Zahlenwerte.
error: true
- conditions:
- condition: template
value_template: '{{ 1.0 > states(''sensor.openweathermap_uv_index'')|float(0) }}'
sequence:
- service: script.dach_rollos_auf_2
data: {}
- conditions:
- condition: template
value_template: >-
{{ 1.5 > states('sensor.openweathermap_uv_index')|float(0) >= 1.0
}}
sequence:
- service: script.dach_rollos_33_zu_2
data: {}
- conditions:
- condition: template
value_template: >-
{{ ( 2.0 > states('sensor.openweathermap_uv_index')|float(0) >=
1.5 ) and ( states('sensor.dachzimmer_temperatur')|float(none) >
22.5 )}}
sequence:
- service: script.dach_rollos_50_zu_v2
data: {}
- conditions:
- condition: template
value_template: >-
{{ (2.5 > states('sensor.openweathermap_uv_index')|float(0) >=
2.0 ) and ( states('sensor.dachzimmer_temperatur')|float(none) >
23 ) }}
sequence:
- service: script.dach_rollos_66_zu_v2
data: {}
- conditions:
- condition: template
value_template: >-
{{ ( states('sensor.openweathermap_uv_index')|float(0) >= 2.5 )
and ( states('sensor.dachzimmer_temperatur')|float(none) > 24 ) }}
sequence:
- service: script.dach_rollos_zu_2
data: {}
default:
- stop: no significant change in state
- delay:
minutes: 15
mode: single
max_exceeded: silent
The automation is triggering different scripts, which set the shutters of two Velux shutters via the Velux integration and a shelly 2.5 via mqtt.
script example
alias: Dach Rollos 66% zu v2
sequence:
- if:
- condition: template
value_template: >-
{{ not ( 38 >= state_attr('cover.velux_rollo_nord_2',
'current_position') >= 28 ) }}
then:
- service: cover.set_cover_position
data:
position: 33
target:
entity_id: cover.velux_rollo_nord_2
- if:
- condition: template
value_template: >-
{{ not ( 33 >= state_attr('cover.velux_rollo_sud', 'current_position')
>= 28 ) }}
then:
- service: cover.set_cover_position
data:
position: 33
target:
entity_id: cover.velux_rollo_sud
else: []
- choose:
- conditions:
- condition: template
value_template: >-
{{ state_attr('cover.lukarne_rollo', 'current_position') > 33 and
not ( 38 >= state_attr('cover.lukarne_rollo', 'current_position')
>= 28 ) }}
sequence:
- service: cover.set_cover_position
data:
position: 33
target:
entity_id:
- cover.lukarne_rollo
- wait_template: '{{ not states("cover.lukarne_rollo") in ["opening", "closing"] }}'
timeout: '00:01:00'
continue_on_timeout: true
- service: cover.open_cover
data: {}
target:
entity_id: cover.lukarne_rollo
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 400
- service: cover.stop_cover
data: {}
target:
entity_id: cover.lukarne_rollo
- conditions:
- condition: template
value_template: >-
{{ state_attr('cover.lukarne_rollo', 'current_position') < 33 and
not ( 38 >= state_attr('cover.lukarne_rollo', 'current_position')
>= 28 ) }}
sequence:
- service: cover.set_cover_position
data:
position: 33
target:
entity_id:
- cover.lukarne_rollo
- wait_template: '{{ not states("cover.lukarne_rollo") in ["opening", "closing"] }}'
timeout: '00:01:00'
continue_on_timeout: true
- service: cover.close_cover
data: {}
target:
entity_id: cover.lukarne_rollo
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- service: cover.stop_cover
data: {}
target:
entity_id: cover.lukarne_rollo
default: null
mode: single
icon: mdi:window-shutter-open
(As the shelly does not provide a tilt, I need to check, if the blinds are going up or are comming down. Hence the complicated script. )
What would happen, if the input sensors do not provide a number, but a string, such as “none” or “unknown”? Any feedback is highly welcome.
Chris