The only think that needs to be costumized is the .items file. You substitute the LivingRoom part with anything you want and you leave the part after the _ the same.
Also in the items file you change the XXXX_Protocol "PUT YOUR PROTOCOL HERE".
The rules follow patterns so you can have as many AC nodes as you wish without messing with the rules.
There is also a timer that wont let you send more that 1 command per second.
This example uses the 1.x mqtt binding, if i transfer it to 2.x i will post it here.
ac.items
Code: Select all
Group Ghome "Home" <house>
Group:String gAC "All AC In the House [%d]" <snow> (Ghome)
String LivingRoom_Protocol "GREE" (gAC) //put in the label the protocol name
Switch LivingRoom_Power "Power" (gAC) // mode of operation - one of Auto/Dry/Cool/Heat/Fan/Night
String LivingRoom_Mode "Mode [%s]" (gAC)
Number LivingRoom_Temp "Temp [%.0f °C]" (gAC) // temperature set point
String LivingRoom_Fan "Fan [%s]" (gAC) // fan mode - one of Auto/F1/F2/F3/F4/F5
String LivingRoom_Swing "Swing [%s]" (gAC) // swing mode - one of Off/UpDown
String LivingRoom_IR "Living Room IR" (gAC) ["Switchable"] {mqtt=">[broker:ESP_Easy/LivingRoomNode1/cmd:command:*:default]"}
Code: Select all
var Timer acCommandDelay = null
rule "AC state changed"
when
Member of gAC received command
then
//logInfo("AC", "------------"+triggeringItem.name +" changed to " + triggeringItem.state)
var baseItemName= triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))
var protocol =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Protocol")]
var power =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Power")]
var mode =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Mode")]
var temp =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Temp")]
var fan =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Fan")]
var swing =gAC.members.findFirst[name.equals(triggeringItem.name.substring(0,triggeringItem.name.lastIndexOf("_"))+"_Swing")]
//val spower = transform("MAP", "truefalse.map", power.state.toString)
if (protocol.label==NULL){return}
if (power.state===NULL){postUpdate(power.name,OFF)}
if (temp.state===NULL){postUpdate(temp.name,"22")}
if (fan.state===NULL){postUpdate(fan.name,"auto")}
if (swing.state===NULL){postUpdate(swing.name,"auto")}
if(acCommandDelay!==null) {
acCommandDelay.cancel
acCommandDelay===null}
acCommandDelay=createTimer(now.plusSeconds(1))[ //dont send the command right away, maybe the user is not fineshed yet
sendCommand( baseItemName +"_IR", "IRSENDAC,'{\"protocol\":\""+protocol.label+"\",\"power\":\""+power.state.toString+"\",\"mode\":\""+mode.state+"\",\"temp\":"+temp.state+",\"fanspeed\":\""+fan.state+"\",\"swingv\":\""+swing.state+"\"}'")
]
end
Code: Select all
Default item=LivingRoom_Power
Switch item=LivingRoom_Mode mappings=[cold="Cold" , hot="Hot", dry="Dry", fanonly="Fan Only", auto="AUTO"]
Setpoint item=LivingRoom_Temp minValue=16 maxValue=30 step=1
Switch item=LivingRoom_Fan mappings=[min="Lowest" , low="Medium", high="High", max="Max", auto="AUTO"]
Switch item=LivingRoom_Swing mappings=[min="Lowest" , low="Medium", high="High", max="Max", auto="AUTO"]