Hi all.
I’m chewing on a problem which I’m sure several of you have solved before:
My solar energy inverter sends uptime in two separate modbus channels (Things), one being the Hi-Value the other being the Lo-Value each being an uint16 (unsinged integer 16), the values come as 0.5second units.
Big question now is how to best combine the two values into a single value representing uptime in seconds.
Here’s what I did so far (but I’m sure there’s a better way):
- receive both values (HI and LO) in 2 Things with a transformation to convert 0.5s to seconds
- Have three items, two to link to the two things (one for HI, one for LO value), the third to hold the actual uptime
- have rule to calculate the actual uptime value based on hi and lo value items
Things file:
Bridge modbus:serial:SPH10000 "Growatt SPH10000" [ port="/dev/ttyUSB0", id=1, baud=9600, stopBits="1.0", parity="none", dataBits=8, encoding="rtu", timeBetweenTransactionsMillis=1000 ]
{
Bridge poller ProduktionsDaten2 "Produktions-Daten" [start=57, length=2, type="input", refresh=60000, maxTries=2] //start=608, length=1, refresh=12000, type="holding", maxTries=2 ]
{
Thing data workTimeTotalHi "Betriebszeit Hi" [readStart="57", readValueType="uint16", readTransform="JS:divide_2.js"] //kommt als 0.5sec
Thing data workTimeTotalLo "Betriebszeit Lo" [readStart="58", readValueType="uint16", readTransform="JS:divide_2.js"] //kommt als 0.5sec
}
JS-Transformation divide_2.js:
(function(s){
s = s / 2;
return s;
})(input)
Items:
Number growattSphWorkTimeTotalHi "Betriebsdauer Hi"
{channel="modbus:data:SPH10000:ProduktionsDaten2:workTimeTotalHi:number"}
Number growattSphWorkTimeTotalLo "Betriebsdauer Lo"
{channel="modbus:data:SPH10000:ProduktionsDaten2:workTimeTotalLo:number"}
Number:Time growattSphWorkTimeTotal "Betriebsdauer"
The rule:
rule CalcRuntime
when
Item growattSphWorkTimeTotalHi changed
or
Item growattSphWorkTimeTotalLo changed
then
growattSphWorkTimeTotal.postUpdate(growattSphWorkTimeTotalHi.state as Number * 65536 + growattSphWorkTimeTotalLo.state as Number)
end
Does anybody have a recommendation as to how to improve and/or simplify this task (e.g. eliminating the necessity for a rule)?
There are many more channels being sent as HI and LO in two separate channels, since I don’t want to create a mass of rules to combine HI and LO for each measurement being sent I’m looking for a solution which can easily be applied to all of those (and I want to avoid a ton of rules for all these).
Looking forward hearing your thoughts!
Kind regards,
Ralph…