I have a Zigbee device (Sonoff TRVZB) which in Z2M has an entity (“weekly_schedule”) that returns a state (json) of more than 255 characters. I can edit this state via Z2M but the entity in HomeAssistant is always cut off after 255 characters, resulting in invalid json so it’s unusable.
My idea was to create a template binary sensor that listens to the MQTT topic for this state and populates a “weekly_schedule” attribute of the binary sensor with the content of the topic, since the attribute size is not limited. Will this approach work? If so, any pointers on the code? I’ve tried something along the lines of:
Because that is not the trigger. Triggered template sensors only update when the trigger occurs, not when an entity in the template changes (as for template sensors without triggers).
Also there is no {{ value }} variable for that template. You could use {{ trigger.payload }} but you would be better off just using an MQTT sensor instead. It supports attributes.
This will create a sensor that has the last time it was updated as the main state. And it will have an attribute named full_payload with the topic information.
Manual mqtt sensors don’t like device_class or state. Also, since the state was getting set by the content of state_topic, and this was longer than 255 characters, it was throwing a warning in the logs. I resolved this by changing the state_topic to the device’s availability topic, which returns {“state”: “:online”}.
I had to fiddle with the correct formatting for the json_attributes_template as I kept getting “Erroneous JSON” errors. The result works fine. I am contemplating changing it to {{ value_json.weekly_schedule|to_json }} to reduce the amount of data in the sensor attributes.
it does, you just need a proper state that matches. You could have used what I wrote above for the value_template and the device_class and it would have worked.
and this wouldn’t have happened if you used what I wrote above as well.
The result just needs to be JSON. So you could have just used {{ value }} if you intended to just output the topic contents as the attributes.