[SOLVED] How measure electricity and water consumption with pulse counters? (2000i/KWh and 20i/liter)

Yes you need 3 items

Number KwhAct "Kwh Actual [%.0f Kwh]" (Floor)
Number KwhMinAvg "Kwh Average [%.0f Kwh]" (Floor)
Number ElecCounter "Elec Counter [%d]" (Floor)

Nearly done,
only the format of the read values seems not able to be correct interpreted:
Cannot convert ‘JSONPATH’ to a state type which item ‘KwhAct’ accepts: [DecimalType, QuantityType, UnDefType].
Cannot convert ‘JSONPATH’ to a state type which item ‘KwhMinAvg’ accepts: [DecimalType, QuantityType, UnDefType].
Cannot convert ‘JSONPATH’ to a state type which item ‘ElecCounter’ accepts: [DecimalType, QuantityType, UnDefType

Values are: “KwhAct: 12.458, KwhMinAvg: 3.234, ElecCounter: 32154433”
(Kwh’s values has 3 decimal after the “.”, Counter is int)

My fault:

rule "Update data"
when
    Time cron "0 * * ? * * *" // Every minute
then
    val jsonString = executeCommandLine("./patchtoscript/menergy_show_data.sh", 1000)
    KwhAct.postUpdate(transform("JSONPATH", "$.KwhAct", jsonString))
    KwhMinAvg.postUpdate(transform("JSONPATH", "$.KwhMinAvg", jsonString))
    ElecCounter.postUpdate(transform("JSONPATH"), "$.ElecCounter", jsonString))
end
1 Like

I’m sorry, but:

Cannot convert ‘{ KwhAct: 2.485, KwhMinAvg: 1.285, ElecCounter: 10002 }’ to a state type which item ‘KwhAct’ accepts: [DecimalType, QuantityType, UnDefType].

Cannot convert ‘{ KwhAct: 2.485, KwhMinAvg: 1.285, ElecCounter: 10002 }’ to a state type which item ‘KwhMinAvg’ accepts: [DecimalType, QuantityType, UnDefType].

Cannot convert ‘{ KwhAct: 2.485, KwhMinAvg: 1.285, ElecCounter: 10002 }’ to a state type which item ‘ElecCounter’ accepts: [DecimalType, QuantityType, UnDefType].

:frowning:

Is the JSONPATH transformation service installed? (In the paper UI)

Not until now,
installed and works.

Thx a lot, now I have a good basic to go on!!

Cool, please mark the thread as solved, thanks

Shure,
and maybe you will remove the bad ) in the code you post, if another user copy&paste he/she run in problems …
( …JSONPATH") … in the ElecConter-line )