Hi. I’m setting up a light that uses MQTT in my config - I can get it to turn on/off and now I want to control RGB and brightness. The light and MQTT are running on my Ninja Sphere (Beagle Bone Black running Ubuntu 14.04).
MQTT message for brightness: "{"method": "set","params":[0.606],"id":"123","jsonrpc":"2.0"}"
and RGB: "{"params":[{"mode":"hue","hue":62.239,"saturation":0.827}],"jsonrpc":"2.0"}"
So I should be looking into using templates to get HA to construct messages like this, yes? How can I find out what to use for things like brightness, hue, saturation values? Thanks.
The documentation says “brightness_value_template (Optional): Defines a template to extract the brightness value.”
This sounds like it’s just for extracting the value, but I need to be able to set it in a particular message.
It looks like that template does also set the outgoing message… I’ve used:
brightness_value_template: ‘{“method”: “set”,“params”:[{{value|int / 255}}],“id”:“123”,“jsonrpc”:“2.0”}’
which seems to produce the right message but causes a Python error:
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/mqtt.py", line 92, in brightness_received
device_value = float(templates['brightness'](payload))
ValueError: could not convert string to float: '{"method": "set","params":[0.5137254901960784],"id":"123","jsonrpc":"2.0"}'
I looked through the HA Python code, and it seems that the payloads have to match exactly for on/off to be recognised.
So, my payload_on in HA config is: {"id": "123", "jsonrpc": "2.0", "method": "set", "params": [true]}
but the Ninja Sphere sends it like: {"id": "123", "jsonrpc": "2.0", "method": "set", "params": [true], "time": 1234567}
which means HA does not think it’s an on/off call.
Can I use a template to strip the extra JSON data (how?), or is there something else I should be doing? Like making a custom component? Thanks.
I’m not sure what to do now. Any ideas? Thanks!