Copied and renamed Sensor isn't working


my name is Christoph an I’m new to Home Assistant. I’m slowly progressing and learn how to edit the config.yaml. But now I’m stuck.
I’ve managed to build a simple sensor(strom_total) which sums all power signals to one total power consumption. (Shelly 3EM). This surely sounds like the simplest task for the most of you guys, but for me this is my first success. :slight_smile:

Now I need a second sensor (strom_total_over1500) which only shows the power consumption higher than 1500W (if the value is lower than 1500 it should send 0.0). This is as well working as expected.

And here ist my Problem. For a third sensor (strom_total_BZ) I copied the second sensor an changed its definition to calculate the difference between the actual Power and 1500W for the case that my overall power consumption is lower than 1500.

If I try to restart an get this third sensor working I receive an error message “invalid config” and I can not find the reason… searched other topics, read the documentations, tried to stick to the same syntax which works for the second sensor without any issues.

I hope you guys could help me out. Thank you in advance.

      friendly_name: "Leistung Hausanschluss"
      value_template: "{{ (states('sensor.shellyem3_c45bbe7989b8_channel_a_power')|float + states('sensor.shellyem3_c45bbe7989b8_channel_b_power')|float + states('sensor.shellyem3_c45bbe7989b8_channel_c_power')|float)}}"
      unit_of_measurement: W

      friendly_name: "Stromverbrauch_kwh"
      value_template: "{{ (states('sensor.shellyem3_c45bbe7989b8_channel_a_energy')|float + states('sensor.shellyem3_c45bbe7989b8_channel_b_energy')|float + states('sensor.shellyem3_c45bbe7989b8_channel_c_energy')|float)}}"
      unit_of_measurement: kWh

      friendly_name: "Leistung über 1500"
      value_template: >
        {% if states("sensor.strom_total")|float > 1500  %}
          {{ (states("sensor.strom_total")|float - 1500)}}
        {% else %} 0.0 
        {% endif %}
      unit_of_measurement: W

    # strom_total_BZ:
    #   friendly_name: "Leistungsreserve BZ"
    #   value_template: >
    #     {% if states("sensor.strom_total")|float < 1500  %}
    #       {{ (1500 - states("sensor.strom_total")|float) }}
    #     {% else %} 0.0
    #     {% endif %}
    #   unit_of_measurement: W

The logfile will provide more info on this, please check. The configuration itself looks okay.


this is logfile

2022-01-26 22:11:35 ERROR (MainThread) [homeassistant.config] Invalid config for [template]: invalid slug strom_total_BZ (try strom_total_bz) for dictionary value @ data[‘sensors’]. Got OrderedDict([(‘strom_total’, OrderedDict([(‘friendly_name’, ‘Leistung Hausanschluss’), (‘value_template’, “{{ (states(‘sensor.shellyem3_c45bbe7989b8_channel_a_power’)|float + states(‘sensor.shellyem3_c45bbe7989b8_channel_b_power’)|float + states(‘sensor.shellyem3_c45bbe7989b8_channel_c_power’)|float)}}”), (‘unit_of_measurement’, ‘W’)])), (‘strom_total_kwh’, OrderedDict([(‘friendly_name’, ‘Stromverbrauch_kwh’), (‘value_template’, "{{ (states(‘sensor.shellyem3_c45bbe7989b8_channel_a_energy’)|fl… (See /config/configuration.yaml, line 22).

Problem solved…

I replaced the “BZ” in the sensorname with “bz”

Now it is working as it should.

Are you not allowed to use capital letters for sensor names?


BTW, this can be simplified to

value_template: "{{ (states('sensor.strom_total') | float - 1500) | max(0) }}"
1 Like