Is there a better way to import this as integer, on the MQTT channel properties?
I think it can be done by profile use on the OH item?
usint48 is an unusuall data type and not sure how to handle. I try to avoid a proxy item, i think there is a better solution.
(function(data) {
if(data == "NULL" || data == "UNDEF") return data;
return parseInt(data) / 100; // Convert to kWh
})(input)
The reading for CurrentSummationDelivered i think its 10W units so i am converting the reading to kWh while i am converting from String (channel reading) to Item value.
I just set kWh as Item unit and itās ok.
I hoped someone else was using these Blitzwolf sockets to give me confirmation.
So i only get the total (historical) reading for energy consuption, i will use this to get a daily consumption every midnight.
I will also get the Power reading from the socket but i have to manually poll every socket. I think this is because of latest firmware changes.
No big deal, i made a rule to kick every two minutes.
The forum is usually much more active during the week.
It is very unclear what you are all doing here.
The usual approach for something like this would be:
use a number MQTT Channel type
set the unit on the MQTT Channel to daWh (deca Watt hours) (see the Metric Prefixes table at Units Of Measurement | openHAB)
set the unit of the Item to kWh and the state description pattern to %.0f %unit%
If you tell OH what the units are originally and what unit you want and how you want to show it, you donāt need a transformation to convert between units or anything like that. Thatās the point of UoM.
As usual you have the best experience, i didnāt think of daWh (deca Watt hours).
My main question was if i could to the string to integer tranformation on the MQTT binding only, without the need for a JS transformation with just one line for the
parseInt(data);
As i said, i pull a string from MQTT. I guess itās the only way to pull a uint48 number?
If you use a number Channel instead of a string Channel it will be parsed into a number automatically.
Choose ānumber valueā when creating the Channel.
As long as the result of your transformationPattern returns the String of a parsable number, it will be parsed into a number for you. You donāt need to parse the Item itself in a transformation.
All transformations always return Strings all the time anyway. If the Channel is something other than a String, OH will parse it.
[WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ā0x0000000000CFā from channel āmqtt:topic:MQTT1:ZigBee2Tasmota:SHP15-test-energyā not supported by type āNumberValueā: Character x is neither a decimal digit number, decimal point, nor āeā notation exponential mark.
I also use this Smart Plug for a while an didnāt need to transform or trigger anything. But Iām using Zigbee2Mqtt and that does the polling and mqtt messaging for me. As units I get A for current, W for power and kwh for energy, so no calculation at all is needed.
Btw: There is a similar plug from Nous, that has a little smaller size. For that reason I prefer that now. It works similar in my environment.