Shelly Gen 2 (plus and pro) using MQTT

Hello,

i’m trying to configure the MQTT light for my shelly 1 pm PLUS.

This new models don’t use topics for everything, instead they have a single topic with a json payload…

this is what i have done so far but i am not satisfied…

could you please help me out ?

my biggest problem is that i can’t get the proper state out of the shelly… the state is listed under the " json_attributes_topic: shellies/wardrobe-lamp/status/switch:0 " specifically as {{ value_json.output }} returning true|false …

i can make something show up with “optimistic” but that’s not correct… my issue is that payload_on and payload_off are sent to a different topic, and the result/status is received on another one (as json) so “state_value_template” seems not to work properly as it should match payload_on/payload_off

This is my current light set up. My second step of course, is to take the other sensor data from the attributes and create sensors for energy, temperature, voltage and power

- platform: mqtt
  name: wardrobe-test
  payload_on: '{"id":1, "src": "homeassistant/shelly/wardrobe-lamp", "method": "Switch.Set", "params":{"id":0,"on":true}}'
  payload_off: '{"id":1, "src": "homeassistant/shelly/wardrobe-lamp", "method": "Switch.Set", "params":{"id":0,"on":false}}'
  qos: 1
  state_topic: shellies/wardrobe-lamp/status/switch:0
  state_value_template: "{{ value_json.output }}"
  optimistic: true
  command_topic: shellies/wardrobe-lamp/rpc
  json_attributes_topic: shellies/wardrobe-lamp/status/switch:0

this is how the status topic json looks like, and how the attributes are showed in HA

{
	"id": 0,
	"source": "MQTT",
	"output": true,
	"apower": 58.085,
	"voltage": 240.700,
	"aenergy": {
		"total": 5.688,
		"by_minute": [48.402, 0.000, 0.000],
		"minute_ts": 1634547641
	},
	"temperature": {
		"tC": 46.7,
		"tF": 116.1
	}
}

image