# Device delivering Wh, not kWh, how to deal with, scaling factor

**URL:** <https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944>\
**Category:** Questions & Help\
**Created:** [May 1, 2021, 1:33pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944 "2021-05-01T13:33:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Metatron](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/metatron/32/40136_2.png) [@Metatron](https://community.homey.app/u/Metatron)\
**Post date:** [May 1, 2021, 1:33pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/1 "2021-05-01T13:33:57Z")

</div>

Hello,

I have a Smart Meter, which I read with SMLReader from Github, delivering the data via MQTT.  
It is pushing the power meter data in Wh, not kWh.  
Of course, it is open source and I could change it, but is there another way to change it in Homey?  
What would be the best way? A virtual device with some flow?  
For me the easiest way would be a scaling factor in the MQTT device, but I don’t see this possibility.

Regards, Metatron

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [May 1, 2021, 10:26pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/2 "2021-05-01T22:26:38Z")

</div>

You’re not the first to ask for this functionality in the MQTT Device. I’ll consider adding mathjs to the mix. So allow a calculation/expression somehow to transform the incoming message to the correct capability format.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [May 1, 2021, 11:02pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/3 "2021-05-01T23:02:20Z")

</div>

In case of using a flow, you could do this  
Create a variable, type numeric  
I named it 'Watth 2 kWh

In the example flow, the trigger is “If power changed” from my converter.

Then I calculate ‘Watth 2 kWh’ as ‘vermogen’ (=power) divided by 1,000

Example flow

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [May 1, 2021, 11:43pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/4 "2021-05-01T23:43:05Z")

</div>

Using a flow, the case of @Metatron would be:

1. Create a virtual device with the measure\_power capability
2. Use the ‘on message received’ flow card from the MQTT Client app, to listen to the mqtt topic containing the power value.
3. (If JSON) grab the value from the JSON input
4. Convert Wh to kWh
5. Update the capability of the virtual device
6. Repeat for all capabilities of the device

This is exactly what the MQTT device from the MQTT Hub handles for you. Of course with the exception of the conversion (step 4), hence this thread. Adding this as a configuration option for the MQTT Device is a valid request.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [May 3, 2021, 2:01pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/5 "2021-05-03T14:01:25Z")

</div>

@Metatron math expressions are implemented in MQTT Hub v3.4.0.

For an example see:

> [@MQTT Hub/Gateway](https://community.homey.app/t/mqtt-hub-gateway/6766/952):
>
> Version 3.4.0 MQTT Device: allow [mathJS](https://mathjs.org/) expressions as value template for incoming messages Both [mathJS](https://mathjs.org/) & [jsonPath](https://github.com/dchester/jsonpath) expression are allowed as value template for incoming messages. The value is accessible via the value param if the message is a raw value. If the message is JSON formatted: path.within.json can be used to target the value. Example: Convert incoming Wh to kWh

---

<div class="post-metadata">

**Author:** ![Metatron](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/metatron/32/40136_2.png) [@Metatron](https://community.homey.app/u/Metatron)\
**Post date:** [May 3, 2021, 5:23pm UTC](https://community.homey.app/t/device-delivering-wh-not-kwh-how-to-deal-with-scaling-factor/46944/6 "2021-05-03T17:23:32Z")

</div>

This is exactly what I wanted/needed, thank you!  
So fast, I am impressed!
