I’m working with a relay board that reports its state as an array of binary values, so [ 0, 0, 0, 0, 0, 0, 0, 0 ]
. What’s the recommended way of dealing with this? It looks like I can brute-force it with something like value_json[0]
, value_json[1]
, … but I’m wondering whether there’s a better way to handle this, or do I need a - binary_sensor:
entry for each value in the array as per the MQTT binary sensor page?
Te best way is the way you understand and can manage. There are many ways, and none is much ‘better’ than the others.
With MQTT you can set discover and use MQTT switch, you can use MQTT booleans, you can store a number and decode it to binary and pass all the switch states at once (probably). Without the actual hardware I don’t know what I would do. The world of MQTT / HA is your canvas…
I realise there’s lots of options, which is why I was asking if there’s a recommended/best-practice way to handle this. The MQTT broker gives you [ 0, 0, 0, 0, 0, 0, 0, 0 ]
for the relay contacts, there’s no ability to change things at the MQTT level, and extracting a bit/binary-sensor at a time from a JSON array, requiring repeated reads of an MQTT value, seems a bit clunky when you’ve already got all the info in place in a single value.