Hi, I’m new to HA.
I wish to set a switch on, if the current and forecast temperature are below defined value.
I get this error:
Message malformed: extra keys not allowed @ data['action'][0]['service']
Here is my attempt:
alias: 07:00 Heizung ON
description: ""
trigger:
- platform: time
at: "07:00:00"
condition:
- condition: numeric_state
entity_id: sensor.temp_keller_aussen_temperature
below: 10
action:
- service: weather.get_forecasts
target:
entity_id: weather.forecast_home
data:
type: hourly
response_variable: forecast_data
{% set n_forecast_temp = forecast_data['weather.forecast_home'].forecast[2].temperature %}
if: "{{ n_forecast_temp < 18 }}"
then:
- type: turn_on
device_id: 24685f36cd61d3052cc025697ad0819d
entity_id: 7339dce48115e69a5f626f2798309bfc
domain: switch
- service: notify.matrix_notify
metadata: {}
data:
message: Heizung ON
mode: single
Thanx for hints and help!
this can be simplfied, but keeping your format and just fixing it…
alias: 07:00 Heizung ON
description: ""
trigger:
- platform: time
at: "07:00:00"
condition:
- condition: numeric_state
entity_id: sensor.temp_keller_aussen_temperature
below: 10
action:
- service: weather.get_forecasts
target:
entity_id: weather.forecast_home
data:
type: hourly
response_variable: forecast_data
- if:
- condition: template
value_template: >
{% set n_forecast_temp =
forecast_data['weather.forecast_home'].forecast[2].temperature %}
{{ n_forecast_temp < 18 }}
then:
- type: turn_on
device_id: 24685f36cd61d3052cc025697ad0819d
entity_id: 7339dce48115e69a5f626f2798309bfc
domain: switch
- service: notify.matrix_notify
data:
message: Heizung ON
mode: single
also, i’m presuming you know what you are doing and what you want wrt the logic side (e.g. forecast[2]) and just asking about how to do the templating right…
1 Like
one additional thing… you should avoid device id’s. here’s why and how. it’ll help you in the long run:
Background
When you start writing automations, a device trigger seems the obvious choice. Everybody knows what a device is and it comes at the top of the UI dropdown list.
[image]
It works… but it is certainly not a “great way to start” because it is storing up problems for the future. Far better to use an entity, with state or numeric_state.
Device_id problems
The yaml will be longer and harder to follow, which may make maintenance difficult, especially a few months down the line when y…
Thanx a lot!
With forecast[2].temperature
I’m checking, how the temp will be 2 hours later.
If it rises, the heating should stay off.
The exact values are still to be determined
great. since this is the first time you’ve posted in this community, if that solved your problem, pls mark the post above as “solution” which will associate the solution to your first post which will then help anyone else who comes across it this.
That’s, for now, a little bit hard to me.
Will it be enough to change from
- type: turn_on
device_id: 24685f36cd61d3052cc025697ad0819d
entity_id: 7339dce48115e69a5f626f2798309bfc
domain: switch
to
- type: turn_on
entity_id: sensor.temp_keller_aussen_temperature
domain: switch
no… you’re trying to turn on a switch, right? what’s the entity name of that switch? you’re not trying to turn on a sensor.
it would be something like this:
- service: switch.turn_on
target:
entity_id: switch.name_of_your_switch_entity
Ahh, sorry, my confusion.
The entity_ID of the switch is in my case
switch.none_sonoff_2
then is this what you want?
(note that i adjusted the indentation on the “then” clause. i just noticed that you had it outdented, which means that it would run always… not part of the “if”
alias: 07:00 Heizung ON
description: ""
trigger:
- platform: time
at: "07:00:00"
condition:
- condition: numeric_state
entity_id: sensor.temp_keller_aussen_temperature
below: 10
action:
- service: weather.get_forecasts
target:
entity_id: weather.forecast_home
data:
type: hourly
response_variable: forecast_data
- if:
- condition: template
value_template: >
{% set n_forecast_temp =
forecast_data['weather.forecast_home'].forecast[2].temperature %}
{{ n_forecast_temp < 18 }}
then:
- service: switch.turn_on
target:
entity_id: switch.none_sonoff_2
- service: notify.matrix_notify
data:
message: Heizung ON
mode: single
Thank you for your friendly advise!
1 Like