Template error - adding sensor values and converting values into %

knx:
- name: "Pixa Zone 1"
      state_address: "11/3/200"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 2"
      state_address: "11/3/201"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 3"
      state_address: "11/3/202"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 4"
      state_address: "11/3/203"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 5"
      state_address: "11/3/204"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 6"
      state_address: "11/3/205"
      type: 1byte_unsigned
      sync_state: 5

template:
  - sensor:
      name: "pixa_personenanzahl"
      state: "{{ states('sensor.pixa_zone1') | float + states('sensor.pixa_zone2') | float + states('sensor.pixa_zone3') | float + states('sensor.pixa_zone4') | float + states('sensor.pixa_zone5') | float + states('sensor.pixa_zone6') | float}}"

I have a problem when adding multiple sensor data to a new entity. With the template code I provided above, I can create a new entity, but the data is not displayed (not available).

Additionally, I have these two additional codes. Can you tell me what the errors are here?

- sensor:
    - name: "pixa_personenanzahl"
      unique_id: "Pixa Personenanzahl"
      state: >-
        {% set persons = states('sensor.pixa_personenanzahl') | float(0) %}
        {{ ((persons - 2) / 0,13) | round(0)}}

  - sensor:
    - name: "temperatur_ist"
      unique_id: "Temperatur RTC"
      state: >-
        {% set temperature = states('sensor.temperatur_ist') | float(0) %}
        {{ ((temperature - 18) / 0,08) | round(0)}} `

Post the full configuration of the template section without breaking it apart like you did.

The only thing I notice is that you have 2 sensors with the same name, which will result in an entity with an _2 at the end.

Outside that, your first pixa_personenanzahl entity can be made in the UI without templates as a sensor group helper with sum selected.

1 Like
knx:
  sensor:
    - name: "CO2"
      state_address: "11/3/10"
      type: ppm
      sync_state: 5

    - name: "Humidity"
      state_address: "11/3/11"
      type: humidity
      sync_state: 5

    - name: "co2 in prozent"
      state_address: "11/3/206"
      type: percent
      sync_state: 5

    - name: "humidity in prozent"
      state_address: "11/3/207"
      type: percent
      sync_state: 5

    - name: "temperatur_ist"
      state_address: "11/3/0"
      type: temperature
      sync_state: 5

    - name: "Pixa Zone 1"
      state_address: "11/3/200"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 2"
      state_address: "11/3/201"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 3"
      state_address: "11/3/202"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 4"
      state_address: "11/3/203"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 5"
      state_address: "11/3/204"
      type: 1byte_unsigned
      sync_state: 5

    - name: "Pixa Zone 6"
      state_address: "11/3/205"
      type: 1byte_unsigned
      sync_state: 5

template:
  - sensor:
    - name: "pixa_personenanzahl"
      unique_id: "Pixa Personenanzahl"
      state: >-
        {% set persons = states('sensor.pixa_personenanzahl') | float(0) %}
        {{ ((persons - 2) / 0,13) | round(0)}}

  - sensor:
    - name: "temperatur_ist"
      unique_id: "Temperatur RTC"
      state: >-
        {% set temperature = states('sensor.temperatur_ist') | float(0) %}
        {{ ((temperature - 18) / 0,08) | round(0)}}
´´´

I added the sum helper and it worked. so the only problem is the converting the value into %

Numbers in templates use decimal . not ,.

i.e. 5 and and half in templates is 5.5 not 5,5

1 Like
template:
    - sensor:
    - name: "pixa_personenanzahl"
      unique_id: "Pixa Personenanzahl"
      state: >-
        {% set persons = states('sensor.pixa_personenanzahl') | float(0) %}
        {{ ((persons - 2) / 0.13) | round(0)}}

    - sensor:
    - name: "temperatur_ist"
      unique_id: "Temperatur RTC"
      state: >-
        {% set temperature = states('sensor.temperatur_ist') | float(0) %}
        {{ ((temperature - 18) / 0.08) | round(0)}}
´´´

if i watch the logs i get this error
Invalid config for 'template' at configuration.yaml, line 78: 'name' is an invalid option for 'template', check: name Invalid config for 'template' at configuration.yaml, line 80: 'state' is an invalid option for 'template', check: state
Invalid config for 'template' at configuration.yaml, line 85: 'name' is an invalid option for 'template', check: name Invalid config for 'template' at configuration.yaml, line 87: 'state' is an invalid option for 'template', check: state

you removed the proper indenting from your first post.

template:
  - sensor:
    - name: "pixa_personenanzahl"
      unique_id: "Pixa Personenanzahl"
      state: >-
        {% set persons = states('sensor.pixa_personenanzahl') | float(0) %}
        {{ ((persons - 2) / 0.13) | round(0)}}

  - sensor:
    - name: "temperatur_ist"
      unique_id: "Temperatur RTC"
      state: >-
        {% set temperature = states('sensor.temperatur_ist') | float(0) %}
        {{ ((temperature - 18) / 0.08) | round(0)}}
1 Like

got it. it works now thank you

If i show the result on my homepage it shows the exact number but it doesnt have the % sign at the end. Is it possible to add it? Because im using the Max combiner and if the result doesnt have the % sign the max combiner just ignores it

Add unit_of_measurement: % and device_class: percent to your template entities.

1 Like

´´´
template:

  • sensor:

    • name: “Personenanzahl in Prozent”
      unique_id: “Pixa Personenanzahl”
      state: >-
      {% set persons = states(‘sensor.personenanzahl_total’) | float(0) %}
      {{ ((persons - 2) / 0.13) | round(0)}}
      unit_of_measurement: “%”
      device_class: “percent”
  • sensor:

    • name: “Temperatur ist in Prozent”
      unique_id: “Temperatur RTC”
      state: >-
      {% set temperature = states(‘sensor.temperatur_ist’) | float(0) %}
      {{ ((temperature - 18) / 0.08) | round(0)}}
      unit_of_measurement: “%”
      device_class: “percent”
there are errors if i dont use the " " but now the template as a whole doesnt work

´´´
template:

  • sensor:

    • name: “Personenanzahl in Prozent”
      unique_id: “Pixa Personenanzahl”
      state: >-
      {% set persons = states(‘sensor.personenanzahl_total’) | float(0) %}
      {{ ((persons - 2) / 0.13) | round(0)}}%
  • sensor:

    • name: “Temperatur ist in Prozent”
      unique_id: “Temperatur RTC”
      state: >-
      {% set temperature = states(‘sensor.temperatur_ist’) | float(0) %}
      {{ ((temperature - 18) / 0.08) | round(0)}}%
did it like this and it shows the % now