I'm not too sure how to start with this problem, so looking for some direction.
I'm dealing with a Huawei Luna2000 battery, pulling data from it via Modbus and sending some of it on to MQTT
I receive an array of numbers (U16) that represent sets of start times, end times, days of the week on which the interval applies, & a charge/discharge mode flag.
The first number in the array contains the number of declared periods.
The times are easy to deal with but the mode and days of the week are where I struggle.
The mode flag is in the first 8 bits of the U16 binary number, either 1 or 0
Days of the week are coded into the second 8 bits, bytes 0 -7, 0=inactive, 1=active.
Example data from a Debug node:
[5,901,1260,383,720,840,65,720,900,62,1260,1439,383,0,480,383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Decoding this:
5 = number of time periods
901 = minutes since midnight, = 15:01
1260 = 21:00
383 = 0000000101111111 reading from the right we get All days Active (01111111) and mode is discharge (00000001)
If the flag/days was eg 65 we'd get 0000000001000001 meaning Sat & Sun only, and mode = Charge
So I'm after ideas how best to tackle decoding this flag/days data into something I can more easily operate with.
I've looked at a couple of binary-decimal library contribs but not sure which is best suited, or if it might be simpler to use a function node (although my Javascript skills are only slightly above non-existent).
Ultimately I'm looking to be able to query what the current state is.
Check if current time is in between a start/end time and then check if the day is flagged Active, and finally determine if it's a Charge or Discharge mode. Potentially I'll run a flow that checks this periodically and posts a result to MQTT.
I could either poll the Modbus very infrequently to get the current settings then do all the parsing on that stored data. Or I could poll Modbus whenever I want to update the current state. The schedule is only updated maybe monthly or less once it's setup.
It would be nice if I could find a way to read the current state direct from a battery Modbus register, but this doesn't seem to exist.
TIA