Hi, i try to update the state of some items when i recieve from Mqtt Brocker value.
for exemple i recieve pourcent value from dimmer through Mqtt , value for exemple “40”
then trought a rules “update the state” of item physicaly attached and recieve “40” for pourcent values.
Exc; dimmerMqttSubscribe = 40 , then physical Dimmer.sendCommand (40) .This is the idea
i try this trought a rules :
rule "Zigbee dimmer Salle de Gym mqtt"
when Item ZigbeeDimmerSalGymSub received update
then ZigbeeDimmerSalGym.sendCommand("{\"brightness\":" + ZigbeeDimmerSalGymSub.state + "}")
end
but i recieve in frontail this message:
[WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '{"brightness":32}' to a command type which item 'ZigbeeDimmerSalGym' accepts: [PercentType, OnOffType, IncreaseDecreaseType, RefreshType].
I use js transformation service for my zigbee dimmers. To do the same you will need to install the js transformation addon via PaperUI. Then add the examples below in /etc/openhab2/transform and name them whatever.js
To get the brightness:
getZigbeeBrightness.js
(function(x){
var result;
var json = JSON.parse(x);
result = json.brightness * 100 / 255;
return result;
})(input)
To set the brightness:
setZigbeeBrightness.js
```csv
(function(x){
var brightness = x * 255/100;
var result = new Object();
result.brightness = brightness;
return JSON.stringify(result);
})(input)
To get the state:
setZigbeeState.js
```csv
(function(x){
var result = new Object();
result.state = x;
return JSON.stringify(result);
})(input)
thanks a lot for your help ! this is great !
so i try and not succed to the setup , i thing i don’t understood the mqtt topic things , i do whit paperui , also i dont need the commandTopic, my goal is to recieve from incoming topic a"subscribe" value.
And then paste “trought a rules” the same value on a real “item”, i have 2 Rpi but the dongle zigbee for the first Rpi i too fareway of the physical switch.
So i send the command from the first Rpi using “mqtt Publish topic”
then on the second Rpi (the one have the physical zigbee dongle) read from “mqtt subscribe topic” the value recived and “trought a rules” clowning value to value. is like a remote if you wish.
maebe there are best process for doing that ?
but i found this this is very simple but it work “i test many trick and by accident i found”
here is the rule for a switch and a dimmer
rule "Zigbee Switch 1 Ancienne Maison mqtt"
when Item ZigbeeSwitch01AcMaisonSub received update
then
ZigbeeSwitch01AcMaison.sendCommand( ZigbeeSwitch01AcMaisonSub.state )
end
rule "Zigbee Dimmer Ancienne Maison Salle de Gym mqtt"
when Item ZigbeeDimmerSalGymSub received update
then
ZigbeeDimmerSalGym.sendCommand( ZigbeeDimmerSalGymSub.state )
end