Help displaying graph from temperature sensors

In my Home Assistant implementation on Raspberry Pi, I include data from my Davis weather station using the Weather Underground component supplied with Home Assistant. Everything is received and displayed correctly, and when I click on the “Outdoor Temperature” monitored condition I get a nice graph:

I also have a set of ESP8266 based temperature sensors inside my house. They upload their readings, once per minute, to HomeAssistant via a MQTT (also running on my Raspberry Pi).
The readings are displayed correctly in Home Assistant, viz:

However, when I click on any of these sensors in the Home Assistant UI, I get this:

rather than a nice graph. How can I change my setup to display a graph?

Here is a snippet from my configuration.yaml:

And here is the relevant code from my ESP8266 sketch:

// MQTT
const char* mqtt_client_id = “temp_study”; //*** set MQTT Client ***
const char* mqtt_topic = “sensor/temp_study”; //*** set MQTT Topic ***
const char* mqtt_server = “192.168.10.21”;
const char* mqtt_username = “pi”;
const char* mqtt_password = “XXXXXXXX”;

// MQTT function to publish temperature
void publishData(float p_temperature){
// create JSON object
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
// Info: the data must be converted into a string: a problem occurs when using floats …
root[“temperature”] = (String) p_temperature+" \u00B0F"; // u000B0 is degree symbol
//root.prettyPrintTo(Serial);
//Serial.println();
char data[200];
root.printTo(data, root.measureLength() +1);
client.publish(mqtt_topic, data, true);
}

Note that I include a “\u00B0F” (degree symbol+F) in the temperature array that is sent up to MQTT. I’ve tried it with and without that text and it makes no difference to the graph, or lack thereof.

Finally, in case it matters I have included:

introduction:
frontend:
recorder:
purge_days: 1
history:
logbook:

in my configuration.yaml.

I would appreciate any help you can give me to get my ESP8266 temperature sensors to display graphs.

Thanks.

I’d guess converting the temperature to float would do it. Replace your value_template with:

value_template: ‘{{ float(value_json.temperature) }}’

That did not fix it. I waited a couple of days to flush out what was in the database. I have

recorder:
purge_days: 1

Michael

I’ve been having similar problems. I can’t work out what causes some to be nice x/y plots and others to be color bars.

I too have been struggling with a similar problem for a while.

I wanted to import the data from a serial sensor (arduino running custom code) and display it nicely in HASS.
Here’s what I’ve come up with, that actually works.
This sensor reports multiple measurements at once, I used a semicolon as data separator on the serial port.
Then, for each actual measurement, I made a new sensor using templates which extracts the data and converts it to float/bool/… from the string.

sensors:
  - platform: serial
    serial_port: /dev/ttyACM0
    name: weatherstation
    baudrate: 57600

  - platform: template
    sensors:
      weatherstation_temperature:
        friendly_name: 'Outside temperature'
        unit_of_measurement: '°C'
        value_template: "{{ float(states.sensor.weatherstation.state.split(';')[0]) }}"

  - platform: template
    sensors:
      weatherstation_humidity:
        friendly_name: 'Outside humidity'
        unit_of_measurement: '%'
        value_template: "{{ float(states.sensor.weatherstation.state.split(';')[1]) }}"

  - platform: template
    sensors:
      weatherstation_wind:
        friendly_name: 'Wind'
        unit_of_measurement: 'km/h'
        value_template: "{{ float(states.sensor.weatherstation.state.split(';')[2])/230.0 }}"

  - platform: template
    sensors:
      weatherstation_rain:
        friendly_name: 'Rain'
        unit_of_measurement: 'mm'
        value_template: "{{ float(states.sensor.weatherstation.state.split(';')[3])*0.3 }}"

  - platform: template
    sensors:
      weatherstation_battery:
        friendly_name: 'Weatherstation battery warning'
        value_template: "{{ bool(states.sensor.weatherstation.state.split(';')[4]) }}"

And how it now looks:

PS: Dont forget to exclude the actual sensor from the recorder, like so:

recorder:
  exclude:
    entities:
      - sensor.weatherstation

Happy hacking!

Has anyone found a solution? having the same issue.

Here’s what I did to make mine work:

sensor 1:

  • platform: mqtt
    name: “Study Temperature”
    state_topic: “sensor/temp_study”
    unit_of_measurement: °F
    value_template: ‘{{ float(value_json.temperature) }}’

Michael

I added

unit_of_measurement: lbs

to a config and it started tracking a graph.
This may be the key.

Leaving this here in case anyone else has the same issue

3 Likes

Thank you, @Str_Alorman. This solved this issue for me

In Lovelace, I’m trying to add a graph using two DHT sensors. The sensor which is not working for me is providing data via MQTT using an ESP8266. I believe that the problem is that the value is transmitted as a string. I have a second DHT sensor connected to the RPi that is running Home Assistant (called main level). Notice how the value drops out on the graph.

I’ve tried the suggestion from mtwheatley above without success. I also changed the Unit of measurment: lbs per Str_Alorman without success.

. image

//this is the sensor which communicates using the ESP8266
- platform: mqtt
name: “Loft Temperature”
state_topic: “Loft Temperature”
unit_of_measurement: lbs
value_template: ‘{{ float(value_json.temperature) }}

//this is the sensor that is connected directly to the PI
- platform: dht
name: “Main Level”
sensor: DHT22
pin: 11
temperature_offset: 1.58
humidity_offset: 3.4
monitored_conditions:
- temperature
- humidity

This is my Lovelace config:

  • type: history-graph
    title: ‘Temperature’
    hours_to_show: 24
    entities:
    - sensor.loft_temperature
    - sensor.main_level_temperature

I do have the same issue.

If I am adding the same sensor in the history graph Lovelace card twice I can see a normal graph along with a bar-color graph. But after 30 minutes the line graph dissapear , very strange.
Any solution yet for changing the coloured bar graph to a line graph yet?

We need to see your sensor config, the frontend config just puts the things together.