Error: Message malformed: extra keys not allowed @ data['sensor']

Hi, i have done this script from scratch.
i got this error when i try to save:
Message malformed: extra keys not allowed @ data[‘sensor’]

sensor:
  - platform: template
    sensors:
      desired_humidity_min:
        friendly_name: "Desired Humidity Min"
        value_template: >-
          {% set temp = states.sensor.thermometre_bureau_temperature.state %}
          {% if temp <= 16 %} 62
          {% elif temp <= 17 %} 59
          {% elif temp <= 18 %} 56
          {% elif temp <= 19 %} 53
          {% elif temp <= 20 %} 50
          {% elif temp <= 21 %} 47
          {% elif temp <= 22 %} 44
          {% elif temp <= 23 %} 41
          {% elif temp <= 24 %} 38
          {% elif temp <= 25 %} 35
          {% elif temp <= 26 %} 32
          {% elif temp <= 27 %} 29
          {% elif temp > 27 %} 32
          {% endif %}

      desired_humidity_max:
        friendly_name: "Desired Humidity Max"
        value_template: >-
          {% set temp = states.sensor.thermometre_bureau_temperature.state %}
          {% if temp <= 16 %} 65
          {% elif temp <= 17 %} 62
          {% elif temp <= 18 %} 59
          {% elif temp <= 19 %} 56
          {% elif temp <= 20 %} 53
          {% elif temp <= 21 %} 50
          {% elif temp <= 22 %} 47
          {% elif temp <= 23 %} 44
          {% elif temp <= 24 %} 41
          {% elif temp <= 25 %} 38
          {% elif temp <= 26 %} 35
          {% elif temp <= 27 %} 32
          {% elif temp > 27 %} 32
          {% endif %}

automation:
  - alias: "Start Humidifier"
    trigger:
      - platform: numeric_state
        entity_id: sensor.thermometre_bureau_humidity
        below: sensor.desired_humidity_min
    action:
      - service: switch.turn_on
        entity_id: switch.prise_double_humidificateur

  - alias: "Stop Humidifier"
    trigger:
      - platform: numeric_state
        entity_id: sensor.thermometre_bureau_humidity
        above: sensor.desired_humidity_max
    action:
      - service: switch.turn_off
        entity_id: switch.prise_double_humidificateur

it all depends on where you are storing that code.

you say “script” but then you created two sensors and an automation.

where (which specific file) did you place that code?

I think you may need a “-” before desired_humidity_min and desired_humidity_max as they are a list, but you should get an error on that when you load the YAML too.

Thank you for the reply, that didnt fix the problem and get the same error

Blockquote I think you may need a “-” before desired_humidity_min and desired_humidity_max as they are a list, but you should get an error on that when you load the YAML too.

What do you mean ? No sure about your question but this code is in Setting-> Automatisations & Scenes

Blockquote it all depends on where you are storing that code.
you say “script” but then you created two sensors and an automation.
where (which specific file) did you place that code?

Does it exist a debug mode or something else to get more info about the error…?

Just answer the question: where did you write that code?

That suggests to me that you’re trying to use the script editor for general editing of configuration.yaml. It doesn’t work like that.

Alternatively, you can create template sensor helpers like this (note the addition of the |int filter):

and automations like this:

Blockquote
Just answer the question: where did you write that code?

Yeah:

  • you can’t create template sensors in there
  • you don’t put the automation: header in there
  • you can only create one automation at a time in there

Create the template sensors helpers as per my last post, then your first automation should look like this if you’re editing in YAML:

image

alias: Humidificateur on
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.thermometre_bureau_humidity
    below: sensor.desired_humidity_min
condition: []
action:
  - action: switch.turn_on
    target:
      entity_id: switch.prise_double_humidificateur
    data: {}
mode: single

Thank you, know i now more how to interact in HA.

Why ;
data: {}
mode: single

you can explain me what is use for ?

Also does the unit of measurement (%) on sensor.desired_humidity_min change something in the interaction of the trigger or it just to display while we read the sensor graph?

If you type in the configuration without the data: {} and mode: single, save and then re-open the YAML, you’ll see the system has added them. It will also do this if you use the UI blocks to build the automation, rather than YAML.

The data: is a generic key for actions, and included as an empty dictionary even when not required, such as for a simple switch.turn_on.

mode: single is the default automation mode.

The unit of measurement is for display and does not affect the automation trigger. Without any unit, you can’t even get a history graph. The device class is primarily for the icon.

Hi Lavoie005,

Those templates are a lot…

I suggest looking at the
Compensation - Home Assistant.
Integration to generate those sensors. It will give you a continuous curve with just a couple of those entries and clean things up a bit.

Or they can be generated mathematically. This gives the “min” humidity, except it gives 29 for temperatures above 27, which is what I think was intended anyway:

{{ ((29,29+((27-states('thermometre_bureau_temperature')|float(0))*3),62)|sort)[1] }}

and this gives the max:

{{ ((32,32+((27-states('thermometre_bureau_temperature')|float(0))*3),65)|sort)[1] }}

Thx guys a lot for your involvement but my humidificator is my water distillator without the top connect on a smart switch, so it’s boil water and when Running Out of Water the self cut the power.
So after distillator has been stopped the water remain hot and continue to make Steam for an hour. So with this gap between it’s give me enough room for don’t make too much humidity and have condensation on my window in the winter.

If someone need to know this approximation chart is base on the Absolute Humidity and it base on a 21°C @ 50% RH at 89.5 kPa ( Calgary, Alberta air pressure )

If you can do math, I’m sure you can. That integration just asks for matching numbers and does the brainy stuff for you. I leave the brainy stuff to people like you, and Petro that wrote Compensation.