Mqtt state changes to unknown

Hi,

I searched a lot for this but can,'t find a solution:

I am running rtl2mqtt to pick up many temperature sensors around the house and everything works as expected.

Now I added a double-switch to the mix with its own topic and a strange thing happens: As soon as a new state change occurs the state of the other switch changes to unknown, see the following images:

image

image

My config is as follows:

  - platform: mqtt
    state_topic: 'RTL_433/home/schalter'
    name: 'Schalter links'
    value_template: >-
      {% if value_json.id == 38274473 and value_json.unit == 2 %}
        {{ value_json.state }}
      {% else %}
        {{ states('sensor.schalter-links') }}
      {% endif %}
  - platform: mqtt
    state_topic: 'RTL_433/home/schalter'
    name: 'Schalter rechts'
    value_template: >-
      {% if value_json.id == 38274473 and value_json.unit == 3 %}
        {{ value_json.state }}
      {% else %}
        {{ states('sensor.schalter-rechts') }}
      {% endif %}      

Does anybody have a clue what I can change to have both states show at the same time?

Thanks in advance

This:

name: 'Schalter links'

is used by Home Assistant to make an entity like this:

sensor.schalter_links

Notice the underscore character ( _ ) between the two words?

In the value_template, you have specified the names of the sensors using the hyphen character ( - ). Home Assistant understands you have a sensor.schalter_links but sensor.schalter-links is unknown.

In both value-templates, replace the hyphen with an underscore.

        {{ states('sensor.schalter_links') }}


        {{ states('sensor.schalter_rechts') }}

Well @123 thank you so much for you lightning fast response. Of cource! I should have known and feel very dumb now for not noticing, especially since I already have the correct

- sensor.schalter_links

in my Lovelace-ui.yaml…

Doh!