Sensor json output to mini-graph-card integer

i have the following configuration for an MQTT temperature sensor:

  sensor:
    - platform: mqtt
      name: 'Temperature'
      state_topic: "home/temperature"

it is publishing event every minute in the following json format for temp and humidity:

{“t”:“28”,“h”:“45”}

i want to display both in a graph using https://github.com/kalkih/mini-graph-card so i’m using the UI configuration:

https://github.com/kalkih/mini-graph-card

      - type: custom:mini-graph-card
        name: Temperature Sensor (12H)
        hours_to_show: 12
        update_interval: 60
        points_per_hour: 60
        entities:
        - sensor.temperature

The problem is that the graph expects integer values and i have them inside a json response.

What would be the proper way to set this up?

You need to split the two values into separate sensors:

  sensor:
    - platform: mqtt
      name: 'Temperature'
      state_topic: "home/temperature"
      value_template: "{{ value_json.t }}"
      unit_of_measurement: "°C" 

    - platform: mqtt
      name: 'Relative Humidity'
      state_topic: "home/temperature"
      value_template: "{{ value_json.h }}"
      unit_of_measurement: "%" 

You can then use the these two sensors in the graph:

sensor.temperature
sensor.relative_humidity
1 Like

Works great - thanks!