How do i format value for current sensor to display gauge, I'm struggling

Hi there. I’m a student that desperately needs help for a project.

I’m running an ESP32 current sensor that publishes its data to a topic. I can listen to this data in Mosquito Broker:

All I want to do is display this data as a gauge on the dashboard and use the data to trigger some automations. I managed to create the sensor entity in the config file, but when trying to set up the gauge it leaves an error saying “entity is non-nemeric: sensor.current_sensor_1”.

Here the code for the sensor in the config file:

- sensor:
          name: "Current Sensor 1"
          state_topic: "/CurrentSense_1"
          suggested_display_precision: 2
          unit_of_measurement: "A"
          value_template: "{{ value_json.value }}" 

I only started using HA a few days ago, and I’m struggling a bit with yaml.

Any help to get this working would be greatly appreciated : )

Means - the value is not numerical.
Post 2 screenshots:

  • history for this sensor
  • dev tools - set state - select this sensor

How do i obtain its history? Im not sure if there is any history this is my first time adding this sensor :sweat_smile:

I get this after manually setting its state to 20:
image

Does this mean im feeding HA my data in the wrong format? :thinking:

Assume you are getting values for this sensor from somewhere.
Then, if you keep getting it - wait a little, the history will be filled.
Unless you have one update a year…
Anyway - why not posting a screenshot with a history? It already has a value after creation the sensor.

I told you to post a screenshot for Set state. Since you already manually set it to 20 - you have to wait for a real value.

Unknown is all I’ve gotten from the sensor, i found the history:

My ESP32 is constantly outputting a value with a ‘.’ decimal, is that why it doesnt recognise it as a value?

I just manually set the state to 20.5 and it worked, and then 20,5 and i get the error again, so im not sure about the decimal thing then :sweat_smile:

Do you have any errors in Log?
Like “sensor has unit XYZ but has a non numerical value “

Since you are a beginner (we all were) , suggest you:

  1. Create a template sensor with value “10”.
  2. Create two cards - history-graph and gauge - for this sensor.
  3. Set manually values in Dev tools - Set state to ”20.5” and “20,5”.
  4. See what happens to you cards. Also, monitor the Log.
  5. Compare your observations with your user settings for “number format”.

Then you will understand what is a proper number format in your setup.
I never dealt with mqtt - probably a user have to convert strings to expected format…

Log meaning logbook from the sidebar?

How would i create template sensor? :sweat_smile:

No. Log filled with errors and messages.

This is too off topic here)))
Go to HA page, read docs.

I got it working. So for anyone that comes across this noobie issue, it seems its not necessarily value_template that determines received mqtt data format, instead its device_class along with unit_of_measurement line to specify what unit of measurement that is compatible with your selected device class you want to use. List of supported device class formats: Customizing entities - Home Assistant

My new mqtt sensor configuration entry in configuration.yaml ( You need file editor add on or similar if its unclear, it was for me) :

# Example configuration.yaml entry
mqtt:

- sensor:
          name: "Current Sensor 1"
          unique_id: Current_Sense_1
          state_topic: "/CurrentSense_1"
          device_class: current
          suggested_display_precision: 1
          unit_of_measurement: A

Repeat this for any aditional mqtt sensors.

Thank you for trying to help, I didn’t know what question to ask because I’m so new to this, but your replies helped to guide my search.