How can I convert the dimmer value from a decimal to an integer in paper white or items? The image attached shows the paper white configuration. The Dimmer\:%s between 0 and 100 is required to trigger the dimmer with the MQTT ESP module I’m using.
Use %d instead of %s
%d still produces a decimal. Looking at the openHAB guide, a dimmer produces a percentage. I know with the older MQTT one can incorporate a JS to perform some match on a value. How might one use this method with Paper White. i.e.
dimmer.js
(function(i) {
if(input >= 0)
{
return input * 100;
}
else
{
return null;
}
})(input)
This may not be the right past, but it is the only direction I’ve managed to find exploring the forums.
Here’s a example of the the payload
Dimmer\\:0.82000000
The ESP needs a payload of
Dimmer\\:82
I worked this out with Papa on another forum. Here’s the build post http://homeautomation.proboards.com/post/3782/thread
openHAB 2 Items
//ESP Dimmer 1 Switch
Switch ESP01Switch "Josh's Light" <light> (All,Random_Switches) { channel="mqtt:topic:2c214008:ESP01Switch" }
//ESP Dimmer 1 Dimmer
Dimmer ESP01DimmerProx "Josh's Dimmer" <slider> (All,Quick_Access,Random_Dimmers,Morning,BedTime)
Number ESP01Dimmer "Josh's Dimmer" { channel="mqtt:topic:2c214008:ESP01Dimmer" }
{ channel=“mqtt:topic:2c214008:ESP01Dimmer” } will be changed based on you channel information below
openHAB 2 Rules
rule "Dimmer1Correct"
when
Item ESP01DimmerProx changed // slider on UI changed state
then
var Number forESP01 = ESP01DimmerProx.state // value from UI slider, already an integer
if ( forESP01 == 100 ) forESP01 = 99 // catch & correct out-of-bounds value
ESP01Dimmer.sendCommand( forESP01 ) // send integer value to the ESP01 Dimmer
end
Paper UI Channel
Number Channel
MQTT state topic : /esp/dimmer01/pub (based on your initial ESP configuration)
MQTT command topic: /esp/dimmer01/sub (based on your initial ESP configuration)
Outgoing value format: Dimmer:%s