Trying to create an icon_template of a mqtt sensor

Hi,

Have a MQTT sensor with a value (in this case -99)

Tried this in dev-template and it works.

      {% set rssi_level = states("sensor.mate_30_pro_rssi_level")|float %}
      {% if rssi_level == -99 %}
        mdi:sim-off
      {% else %}
        {% if rssi_level >= -90 %}
          mdi:signal-cellular-outline
        {% elif rssi_level > -60 %}
          mdi:signal-cellular-1
        {% elif rssi_level > -30 %}
          mdi:signal-cellular-2
        {% else %}
          mdi:signal-cellular-3
        {% endif %}
      {% endif %}

Completed the sensor setup:

  - platform: mqtt
    name: Mate 30 Pro RSSI Level
    state_topic: "monitor/stue/monitor_stigh_mate30/rssi"
    icon_template: >-
      {% set rssi_level = states("sensor.mate_30_pro_rssi_level")|float %}
      {% if rssi_level == -99 %}
        mdi:sim-off
      {% else %}
        {% if rssi_level >= -90 %}
          mdi:signal-cellular-outline
        {% elif rssi_level > -60 %}
          mdi:signal-cellular-1
        {% elif rssi_level > -30 %}
          mdi:signal-cellular-2
        {% else %}
          mdi:signal-cellular-3
        {% endif %}
      {% endif %}

…then the entire sensor fails…

Can’t figure out what is wrong :frowning:

chnage float to int. Other than that, it looks good. But… just looked at the docs and it looks like icon_template isn’t a valid field for mqtt sensors. So that’sprobably your problem.

2 Likes

Was just about to hit the reply button saying the same thing as you…again.

@TheStigh Leave your MQTT sensor as is and create a template sensor if you want a template_icon. You can use the mqtt sensor for the majority of the template sensor fields.

Hah, I was just giving you shit the other day, don’t worry about it

1 Like

Hi @petro,

Of course it’s you answering first :slight_smile: Happy you’re around!
Hummm… perhaps just make a new template sensor of this sensor then?

Haha, was typing to petro when you replied … yeap, I will.

Actually, just change the device class to signal_strength

device_class: signal_strength

should change the icon without the need to create the template.

1 Like

@petro, supported by mqtt platform?

Yep, every sensor supports device_class

1 Like
  - platform: mqtt
    name: Value Mate 30 Pro RSSI Level
    device_class: signal_strength
    state_topic: "monitor/stue/monitor_stigh_mate30/rssi"

Testing - rebooting now :slight_smile:

Using device_class, give it full signal at -99 :slight_smile:

Will restart my monitor-service and see when it actually connects…

@petro, @jocnnor

It kind’a works, but the negative value might cause the issues…
I never get the signal bar to increase, whatever the value is.
I’ve also tried to re-arrange the order, having -90 at the top.

I’m also uncertain if I say >= -90 what is bigger? -80 or -100 ? In my mind -80 is bigger than -90…

Any ideas?

  - platform: template
    sensors:
      monitor_mate_30_pro_rssi_stue:
        friendly_name: Mate 30 Pro RSSI Stue
        unit_of_measurement: 'dBm'
        value_template: '{{ states("sensor.value_mate_30_pro_rssi_stue") }}' 
        icon_template: >-
          {% set rssi_level = states("sensor.value_mate_30_pro_rssi_stue") | int %}
          {% if rssi_level == -99 %}
            mdi:sim-off
          {% else %}
            {% if rssi_level >= -20 %}
              mdi:signal-cellular-3
            {% elif rssi_level >= -40 %}
              mdi:signal-cellular-2
            {% elif rssi_level >= -65 %}
              mdi:signal-cellular-1
            {% elif rssi_level <= -90 %}
              mdi:signal-cellular-outline
            {% else %}
            {% endif %}
          {% endif %}

You have a gap from -90 to -65 where the template will return nothing.

        icon_template: >-
          {% set rssi_level = states("sensor.value_mate_30_pro_rssi_stue") | int %}
          {% if rssi_level == -99 %}
            mdi:sim-off
          {% else %}
            {% if rssi_level >= -20 %}
              mdi:signal-cellular-3
            {% elif rssi_level >= -40 %}
              mdi:signal-cellular-2
            {% elif rssi_level >= -65 %}
              mdi:signal-cellular-1
            {% else %}
              mdi:signal-cellular-outline
            {% endif %}
          {% endif %}
1 Like

Still, even if the signal are between -20 and -40 I never get other icon than mdi:signal-cellular-outline
Can it be that it doesn’t read correctly what’s inside the if’s ?

Can it be the negative value ?

I assume so…it all works fine in the template editor with negative values.

Try adding:

  entity_id: 
    - sensor.value_mate_30_pro_rssi_stue

I don’t know what to say. It all seems right to me…

1 Like

Resolved :slight_smile: Thnx @jocnnor and @petro

One of the sensor consist of

  - platform: mqtt
    name: Value Mate 30 Pro RSSI Stue
    device_class: signal_strength
    state_topic: "monitor/stue/monitor_stigh_mate30/rssi"

  - platform: template
    sensors:
      monitor_mate_30_pro_rssi_stue:
        friendly_name: Mate 30 Pro RSSI Stue
        unit_of_measurement: 'dBm'
        value_template: '{{ states("sensor.value_mate_30_pro_rssi_stue") }}' 
        icon_template: >-
          {% set rssi_level = states("sensor.value_mate_30_pro_rssi_stue") | int %}
          {% if -1 > rssi_level > -30 %}
            mdi:signal-cellular-3
          {% elif -31 >= rssi_level > -50 %}
            mdi:signal-cellular-2
          {% elif -51 >= rssi_level > -70 %}
            mdi:signal-cellular-1
          {% elif -71 >= rssi_level > -98 %}
            mdi:signal-cellular-outline
          {% else %}
            mdi:signal-off
          {% endif %}

fyi according to most things I’ve read about RSSI, anything better than -50 is ‘the most bars’.

Well, such short distances in this house, so I kind of wanted full bars on very high signal.

Next task will be to make a math calculation to find out what room you are in.
It is possible, theoretically to be connected to all monitors (4 pcs), so to have a sensor showing what room you actually are in should be a calculation.

1 Like

Triangulation using wifi access points…love it!

Tried it ?