Showing value of MQTT Sensor on Lovelace Dashboard

Hi! I have been having issues with just being able to show my humidity and temperature values on lovelace. I have this custom sensor that sends me the temp. & hum. values in millivolts. I am able to make them show in lovelace trought creating the entities like in my configuration.yaml. With this code:

sensor 1:
  platform: mqtt
  state_topic: '/devices/192.168.1.125/ai/1'
  name: 'Temperature'
  unit_of_measurement: '°C'
 
sensor 2: 
  platform: mqtt
  state_topic: '/devices/192.168.1.125/ai/2'
  name: 'Humidity'
  unit_of_measurement: '%'

Screenshot 2020-11-18 104040

NOW… what i need is to show the real temp & hum values, like 24 celcius and 35%… so i went on reading about TEMPLATING to make mathematical calculation on the millivolt values and bring them to readable values. VALUE_TEMPLATE. I have been trying all kinds of different lines of codes that i could find on the forum with no success.

The value_template line is the one i need help with…i show here what i would need it to do…

sensor 1:
  platform: mqtt
  state_topic: '/devices/192.168.1.125/ai/1'
  name: 'Temperature'
  unit_of_measurement: '°C'
  value_template: '{{ (value / 100) -20 }}'
  
sensor 2: 
  platform: mqtt
  state_topic: '/devices/192.168.1.125/ai/2'
  name: 'Humidity'
  unit_of_measurement: '%'
  value_template: '{{ value /100 }}'

THANK YOU!

Can you show what mqtt message you actually receive ?

the same as in the picture of the description.

here a picture of my mqtt explorer when i listen on topic:/devices/192.168.1.125/ai/1’
Screenshot 2020-11-18 151502
Same value as i am able to show in lovelace.

What is missing is the calculation for formatting the values.

Thank you

I really need help on that to continue, please!

I found it ! I am setup for that part ! Lets move on ! :slight_smile:
this is how i wrote it
value_template: ‘{{ (((value_json * 80)/10000) - 17) | round(2) }}’
It is just value_json the value and then i can make mathematicals…!

1 Like