Missing data from a MQTT sensor

I created a MQTT task. The data also arrive at the HA,
but are not displayed. What am I doing wrong?

Home Assistant 0.46.0:

## sensor mqtt kostal
- platform: mqtt
  name: "Kostaldata"
  state_topic: "kostaldata"
  unit_of_measurement: "kWh"
  value_template: "{{ value_json.day_power_kwh }}"
  
 ## debug message
  2017-06-13 07:40:58 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on kostaldata: 
  	{"name":"Kostaldata",
	 "device":"Kostal Piko 5.5",
	 "state":"15796kWh",
	 "attributes":
	    {"Modus":"Einspeisen MPP",
		 "Day_Power_kwh":"0.35kWh",
		 "Total_Power_kwh":"15796kWh",
		 "Current_Power_watt":"309W",
		 "timestamp":"2017-06-13 07:40:58"
		 }
	}

Not an expert here, sorry. I took your info and put it in the Templates page in HASS:

{% set value_json={"name":"Kostaldata",
	 "device":"Kostal Piko 5.5",
	 "state":"15796kWh", "attributes":
	    {"Modus":"Einspeisen MPP",
		 "Day_Power_kwh":"0.35kWh",
		 "Total_Power_kwh":"15796kWh",
		 "Current_Power_watt":"309W",
		 "timestamp":"2017-06-13 07:40:58"
		 }	}%}

{{value_json.attributes.Day_Power_kwh}}

It gives: 0.35kWh

So, have you tried this in the value_template?

"{{ value_json.attributes.Day_Power_kwh }}"

Although I’m not sure if it won’t complain about having numbers and characters mixed together. (In the meanwhile, I’m going to see how to split 0.35kWh and come back).

UPDATE:
This works in the Templates page:

{{value_json.attributes.Day_Power_kwh[:-3]}}

and based on this info for nested JSON in a response this also works:

{{value_json['attributes']['Day_Power_kwh'][:-3]}}

Both methods provide: 0.35

Hi timseebeck,

Thank you, it works now.
There is an easier way to map the attributes.

I still have 37 other sensors and it would be easier if there is a generic method.

2017-06-13 11:29:45 DEBUG (MainThread) [homeassistant.components.mqtt] 
 Received message on kostaldata: 
 	{"name":"Kostaldata",
	 "attributes":
	  {"pikomodus":"Einspeisen MPP",
	   "pikoday":8.81,
	   "pikototal":15804,
	   "pikocurrent":3280,
	   "pikotime":"2017-06-13 11:29:45",
	   "pikodevice":"Kostal Piko 5.5"
	   }
   }

- platform: mqtt
  name: "Piko Tagesleistung"
  state_topic: "kostaldata"
  unit_of_measurement: "kWh"
  value_template: "{{ value_json['attributes']['pikoday'] }}"
 
- platform: mqtt
  name: "Piko Zeit"
  state_topic: "kostaldata"
  value_template: "{{ value_json['attributes']['pikotime'] }}"
 
- platform: mqtt
  name: "Piko Status"
  state_topic: "kostaldata"
  value_template: "{{ value_json['attributes']['pikomodus'] }}" 

- platform: mqtt
  name: "Piko aktuell"
  state_topic: "kostaldata"
  value_template: "{{ value_json['attributes']['pikocurrent'] }}" 
  unit_of_measurement: "W"

- platform: mqtt
  name: "Piko total"
  state_topic: "kostaldata"
  value_template: "{{ value_json['attributes']['pikototal'] }}" 
  unit_of_measurement: "kWh"

Glad you get it working!

(wow, 38 sensors! lots of fun)

Yes, a lot of devices…

1 Like