WiFi RSSI Device Class

Hi,

I noticed under MQTT you can have a sensor with the class of ‘Battery’, this is nice because the icon changes based on the value.

I have created a ESP8266 device that reports its own WiFi signal strength, this is published to MQTT. It would be great to have a WiFi RSSI class that measures in ‘dBm’ and changes the icon based on strength.

The negative value of dBm is somewhat confusing for basic users.
I think signal displayed with the bars might be helpful

Is this worth while?

1 Like

I am actually doing that with the custom template card… the MQTT sensor reports strength from 0-100 but using a template you can convert to dBm and then set the icon according to the strength. I have my Lovelace code for how to do it in that thread for the 100% Templatable something… search 100% template and you’ll see it

David how did you do this template card. I want to show the dbm in the negative form but MQTT shows the RSSI as a positive number. I saw where you did the section in your lovelace for “MQTT & Wifi Connections” but I could not figure out how to convert that from the Lovelace file format to the UI format but from I see it will show the -dB value in the card correct?

I use the custom config-template card

          - type: 'custom:config-template-card'
            variables:
              - states['sensor.sonoff1_2914_status'].attributes['MqttCount']
              - states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount']
              - states['sensor.sonoff1_2914_status'].state
              - states['sensor.sonoff2_3110_status'].attributes['MqttCount']
              - states['sensor.sonoff2_3110_status'].attributes['WiFi LinkCount']
              - states['sensor.sonoff2_3110_status'].state
              - states['sensor.sonoff5_1083_status'].attributes['MqttCount']
              - states['sensor.sonoff5_1083_status'].attributes['WiFi LinkCount']
              - states['sensor.sonoff5_1083_status'].state
              - states['sensor.sonoff6_3719_status'].attributes['MqttCount']
              - states['sensor.sonoff6_3719_status'].attributes['WiFi LinkCount']
              - states['sensor.sonoff6_3719_status'].state
              - states['sensor.nodemcu_lounge_status'].attributes['MqttCount']
              - states['sensor.nodemcu_lounge_status'].attributes['WiFi LinkCount']
              - states['sensor.nodemcu_lounge_status'].state
            entities:
              - sensor.sonoff1_2914_status
              - sensor.sonoff2_3110_status
              - sensor.sonoff5_1083_status
              - sensor.sonoff6_3719_status
              - sensor.nodemcu_lounge_status
            card:
              type: 'custom:hui-entities-card'
              title: MQTT & Wifi Connections
              show_header_toggle: false
              entities:
                - entity: sensor.sonoff1_2914_status
                  name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + vars[0] + '\xa0'.repeat(4) + 'WiFi ' + vars[1] + '\xa0'.repeat(3) + ((parseInt(vars[2]) / 2) - 100 ) + '\xa0' + 'dBm' + '\xa0'.repeat(3) + ( vars[2] >= 100 ? 'Excellent' : vars[2] >= 80 ? 'Good' : vars[2] >= 60 ? 'Fair' : 'Weak' )}"
                  icon: "${vars[2] >= 100 ? 'mdi:wifi' : vars[2] >= 80 ? 'mdi:wifi-strength-3' : vars[2] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"
                - entity: sensor.sonoff2_3110_status
                  name: "${'Toothbrush' + '\xa0'.repeat(7) + 'MQTT ' + vars[3] + '\xa0'.repeat(4) + 'WiFi ' + vars[4] + '\xa0'.repeat(3) + ((parseInt(vars[5]) / 2) - 100 ) + '\xa0' +  'dBm' + '\xa0'.repeat(3) + ( vars[5] >= 100 ? 'Excellent' : vars[5] >= 80 ? 'Good' : vars[5] >= 60 ? 'Fair' : 'Weak' )}"
                  icon: "${vars[5] >= 100 ? 'mdi:wifi' : vars[5] >= 80 ? 'mdi:wifi-strength-3' : vars[5] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"
                - entity: sensor.sonoff5_1083_status
                  name: "${'Garage' + '\xa0'.repeat(15) + 'MQTT ' + vars[6] + '\xa0'.repeat(4) + 'WiFi ' + vars[7] + '\xa0'.repeat(3) + ((parseInt(vars[8]) / 2) - 100 ) + '\xa0' +  'dBm' + '\xa0'.repeat(3) + ( vars[8] >= 100 ? 'Excellent' : vars[8] >= 80 ? 'Good' : vars[8] >= 60 ? 'Fair' : 'Weak' )}"
                  icon: "${vars[8] >= 100 ? 'mdi:wifi' : vars[8] >= 80 ? 'mdi:wifi-strength-3' : vars[8] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"
                - entity: sensor.sonoff6_3719_status
                  name: "${'Alarm' + '\xa0'.repeat(17) + 'MQTT ' + vars[9] + '\xa0'.repeat(4) + 'WiFi ' + vars[10] + '\xa0'.repeat(3) + ((parseInt(vars[11]) / 2) - 100 ) + '\xa0' +  'dBm' + '\xa0'.repeat(3) + ( vars[11] >= 100 ? 'Excellent' : vars[11] >= 80 ? 'Good' : vars[11] >= 60 ? 'Fair' : 'Weak' )}"
                  icon: "${vars[11] >= 100 ? 'mdi:wifi' : vars[11] >= 80 ? 'mdi:wifi-strength-3' : vars[11] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"
                - entity: sensor.nodemcu_lounge_status
                  name: "${'Weather' + '\xa0'.repeat(13) + 'MQTT ' + vars[12] + '\xa0'.repeat(4) + 'WiFi ' + vars[13] + '\xa0'.repeat(3) + ((parseInt(vars[14]) / 2) - 100 ) + '\xa0' +  'dBm' + '\xa0'.repeat(3) + ( vars[14] >= 100 ? 'Excellent' : vars[14] >= 80 ? 'Good' : vars[14] >= 60 ? 'Fair' : 'Weak' )}"
                  icon: "${vars[14] >= 100 ? 'mdi:wifi' : vars[14] >= 80 ? 'mdi:wifi-strength-3' : vars[14] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"

image

2 Likes

Oh thanks that worked great!! Exactly what I was trying to do but you are way better the all the coding than I am.

Now I took what you had to work the device I needed it for but not getting a result am I doing it wrong? This is an manually entered card in the Lovelace UI on the dashboard so things maybe out of order some.

type: 'custom:config-template-card'
variables:
  - states['washer_monitor_sensor_status'].attributes['MqttCount']
  - states['washer_monitor_sensor_status'].attributes['WiFi LinkCount']
  - states['washer_monitor_sensor_status'].state
entities:
  - sensor.washer_monitor_sensor_status
card:
  type: 'custom:hui-entities-card'
  entities:
    - entity: sensor.washer_monitor_sensor_status
      name: "${'Washer' + '\_'.repeat(16) + 'MQTT ' + vars[0] + '\_'.repeat(4) + 'WiFi ' + vars[1] + '\_'.repeat(3) + ((parseInt(vars[2]) / 2) - 100 ) + '\_' + 'dBm' + '\_'.repeat(3) + ( vars[2] >= 100 ? 'Excellent' : vars[2] >= 80 ? 'Good' : vars[2] >= 60 ? 'Fair' : 'Weak' )}"
title: Washer Wifi Connections
show_header_toggle: false

Did you check your sensor has those status attributes? That is how my sonoff switches flashed with Tasmota have them.

Yeah it shows the attributes under the status part of the sensor. I am using Tasmata too on this Sonoff S31 plug. I renamed it for wifi strength but it should be all the attributes or am I missing something?

need to check you have the name right… if you do it will work… see here is my states for one of mine


See how that maps to the template in Lovelace

Ah found it type on my part. When I copied the sensor name it did not copy the “sensor.xxxxx” part. Awesome working great now. I can you pull up time off that attributes too, I see it there but how would you change the code to pull that?

Thanks a bunch for the help, you are the code master…lol

Just duplicate the format of the other attributes… Just remember var[0] is the first variable and there are 3 variables in my example for each sensor so thus var 0-2 so if you add another one it’s var[3] - just follow the format of the other ones.

Ok got it thanks

Hi, I’m trying to get something similar set up for getting the signal strength from my pool controller. Mine is based on an ESP32 board, so I’ve had to modify your code a bit, and didn’t need as many variables for my application (I only want to know the wifi strength and change the icon).

Untitled

Basically, I’d like it to look exactly like the top card, but to change the icon, and maybe say “Pool Controller Wifi Signal: Weak/Fair/Good” in the title, based on the wifi signal strength.

I’m using the following code for the bottom card:

              - type: 'custom:config-template-card'
                variables:
                  - 'states[''sensor.hac1_wifi_signal''].state'
                entities:
                  - sensor.hac1_wifi_signal
                card:
                  type: 'custom:hui-entities-card'
                  show_header_toggle: false
                  entities:
                    - entity: sensor.hac1_wifi_signal
                      name: "${'Pool Controller WiFi Signal' + ((parseInt(vars[0]) / 2) - 100 ) + '\_' + 'dBm' + '\_'.repeat(3) + ( vars[0] >= 100 ? 'Excellent' : vars[0] >= 80 ? 'Good' : vars[0] >= 60 ? 'Fair' : 'Weak' )}"
                      icon: "${vars[0] >= 100 ? 'mdi:wifi' : vars[0] >= 80 ? 'mdi:wifi-strength-3' : vars[0] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"

I’m not sure where it’s getting -130dBm from, since it’s displaying the correct dBm after it (why are there two different numbers)?

Is there a way to adapt this into a standard glance card?:

              - entities:
                  - entity: sensor.hac1_wifi_signal
                    icon: (some sort of voodoo here)
                type: glance

Any help would be appreciated, thanks!

-130 if the state is -60 looks right o me…
But…
With Tasmota, the state is an RSSI and with yours the state is already dB so why are you converting it?

Yeah, I caught that shortly after posting that, sorry haha.

I’ve got it all sorted out now, thanks! I doubt I could’ve got this working without your example.

1 Like

Next, this author’s code doesn’t work. It provides regularly unfinished business. Or just parts unusable from larger units. This code is an example of this. It only unnecessarily takes up space here and mystifies users looking for solutions.
Sir. When presenting some code, especially a card, next time I would like a comprehensive comprehensive and functional solution not just a malfunctioning torso!

The code works perfectly fine, it just requires a custom card (config-template-card) and the custom card won’t display if entities presented to the card do not exist. Next time, ask a question instead of insulting other users on your first post when you can’t figure something out.

2 Likes

Hello,

i want the dynamicSignal strength symbol and words (Excellent/Weak/ … ) like in this topic. Iam using ESPHome with ESP8266 and send the RSSI/Wifi Status in dbm to HomeAssistent. So how i can put your Code in my Code?

I dont want to use Tasmota!

This Options i want:

- entity: sensor.hac1_wifi_signal
                      name: "${'Pool Controller WiFi Signal' + ((parseInt(vars[0]) / 2) - 100 ) + '\_' + 'dBm' + '\_'.repeat(3) + ( vars[0] >= 100 ? 'Excellent' : vars[0] >= 80 ? 'Good' : vars[0] >= 60 ? 'Fair' : 'Weak' )}"
                      icon: "${vars[0] >= 100 ? 'mdi:wifi' : vars[0] >= 80 ? 'mdi:wifi-strength-3' : vars[0] >= 60 ? 'mdi:wifi-strength-2' : 'mdi:wifi-strength-1' }"

This is my Code: