Using MQTT to change speed on a ceiling fan.
I’m using Switch to be able to use buttons in the GUI.
However I can’t get the buttons to recognize what speed is selected. Guessing it has something of how I’m mapping the MQTT in parameter. For each button if it’s 1,2,3,4,5,6.
So in the GUI when pressing speed 2, I want to button to be ‘selected’.
.items
Switch FanSpeed1 "Speed 1" {mqtt="
// First i send to my broadlink to play a command
>[mqtt:broadlink/fans/livingroom/speed-1:command:ON:play],
// Send to keep track what speed is active
>[mqtt:/home/fans/livingroom/speed:command:ON:1],
// Listen if value is 1, then button is on
<[mqtt:/home/fans/livingroom/speed:state:ON:1]
"}
// next button for another speed
Switch FanSpeed2 "Speed 2" {mqtt="
>[mqtt:broadlink/fans/livingroom/speed-2:command:ON:play],
>[mqtt:/home/fans/livingroom/speed:command:ON:2],
<[mqtt:/home/fans/livingroom/speed:state:ON:2]
"}
.sitemap
Switch item=FanSpeed1 label="Speed" mappings=[ON="1"]
Switch item=FanSpeed2 label="Speed" mappings=[ON="2"]
Switch item=FanSpeed3 label="Speed" mappings=[ON="3"]
Switch item=FanSpeed4 label="Speed" mappings=[ON="4"]
Switch item=FanSpeed5 label="Speed" mappings=[ON="5"]
Switch item=FanSpeed6 label="Speed" mappings=[ON="6"]
I’ve made it work for my house state HOME, AWAY, BEDTIME, NIGHT. I did this with MAP(). However I needed to create a new map for each of the states and that seems like a PIK (pain in keyboard).
Switch HouseModeHome "HOME" {mqtt="
>[mqtt:/home/house:command:ON:HOME],
<[mqtt:/home/house:state:MAP(househome.map)]
"}