Page 1 of 1
Controlling AC throught Openhab and ESP Easy
Posted: 13 Jul 2019, 15:16
by jimmys01
This is my setup that utilizes the new extended AC commands of the IR library.
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]"}
ac.rules
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
home.sitemap
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"]
Re: Controlling AC throught Openhab and ESP Easy
Posted: 14 Jul 2019, 00:50
by ThomasB
Thanks for sharing your setup. I'm also using ESPEasy with Openhab home control. Compatibility between them is excellent thanks to MQTT.
And giving a voice to ESPEasy devices is possible using Openhab's Alexa Control Binding. Telling Alexa to control a ESPEasy device and/or have her provide voice responses with useful information about them is all done in rules. If not already using it, I highly recommend the Alexa Control binding. Details are here:
https://community.openhab.org/t/release ... hab2/37844
- Thomas
Re: Controlling AC throught Openhab and ESP Easy
Posted: 31 Jul 2019, 14:04
by 8lazo8
jimmys01 wrote: ↑13 Jul 2019, 15:16
This is my setup that utilizes the new extended AC commands of the IR library.
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]"}
ac.rules
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+"\",\"opmode\":\""+mode.state+"\",\"degrees\":"+temp.state+",\"fanspeed\":\""+fan.state+"\",\"swingv\":\""+swing.state+"\"}")
]
end
home.sitemap
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"]
Thanks Jimmy for sharing this, very useful.
How does an mqtt message looks like in this case? Which plugin do you use in espeasy?
Re: Controlling AC throught Openhab and ESP Easy
Posted: 31 Jul 2019, 21:09
by jimmys01
The plug in is the "Communication - IR Transmit" plug in or else the P035.
The mqtt cmd message is like:
Code: Select all
IRSENDAC,'{"Protocol":"COOLIX","Power":"on","Opmode":"dry","Fanspeed":"auto","Degrees":22,"Swingv":"max","Swingh":"off"}'
Re: Controlling AC throught Openhab and ESP Easy
Posted: 01 Aug 2019, 19:49
by 8lazo8
jimmys01 wrote: ↑31 Jul 2019, 21:09
The plug in is the "Communication - IR Transmit" plug in or else the P035.
The mqtt cmd message is like:
Code: Select all
IRSENDAC,{"Protocol":"COOLIX","Power":"on","Opmode":"dry","Fanspeed":"auto","Degrees":22,"Swingv":"max","Swingh":"off"}
Thanks a lot!
Re: Controlling AC throught Openhab and ESP Easy
Posted: 14 Sep 2019, 23:26
by 8lazo8
jimmys01 wrote: ↑31 Jul 2019, 21:09
The plug in is the "Communication - IR Transmit" plug in or else the P035.
The mqtt cmd message is like:
Code: Select all
IRSENDAC,{"Protocol":"COOLIX","Power":"on","Opmode":"dry","Fanspeed":"auto","Degrees":22,"Swingv":"max","Swingh":"off"}
Hi Jimmy,
I tried the mqtt setup and after all the message/signal reaches the AC but whatever option I send to it, it always turns on in fan only mode at 25 degree celsius.
Did you try this with a Gree AC?
Re: Controlling AC throught Openhab and ESP Easy
Posted: 14 Sep 2019, 23:51
by 8lazo8
8lazo8 wrote: ↑14 Sep 2019, 23:26
jimmys01 wrote: ↑31 Jul 2019, 21:09
The plug in is the "Communication - IR Transmit" plug in or else the P035.
The mqtt cmd message is like:
Code: Select all
IRSENDAC,{"Protocol":"COOLIX","Power":"on","Opmode":"dry","Fanspeed":"auto","Degrees":22,"Swingv":"max","Swingh":"off"}
Hi Jimmy,
I tried the mqtt setup and after all the message/signal reaches the AC but whatever option I send to it, it always turns on in fan only mode at 25 degree celsius.
Did you try this with a Gree AC?
I found the solution for Gree: instead of opmode is only mode, instead of degrees is temp.
Re: Controlling AC throught Openhab and ESP Easy
Posted: 16 Sep 2019, 07:54
by jimmys01
Thanks, leftovers from early versions of the JSON
Re: Controlling AC throught Openhab and ESP Easy
Posted: 14 Nov 2019, 10:21
by jimmys01
A quick note.
The command structure is now like this:
IRSENDAC,'{"protocol":"COOLIX","power":"on","mode":"dry","fanspeed":"auto","temp":22,"swingv":"max","swingh":"off"}'
note the extra '
Furthermore the JSON keys are not case sensitive anymore.
Has anyone made this work with MQTT binding 2.4 for OpenHab?
Re: Controlling AC throught Openhab and ESP Easy
Posted: 25 Nov 2019, 13:30
by jimmys01
This is the MQTT2 binding configuration
AC.things
Code: Select all
Thing mqtt:topic:LivingRoomNode1 "Living Room Node" (mqtt:broker:myMQTTBroker) {
Channels:
Type string : cmd [commandTopic="ESP_Easy/LivingRoomNode1/cmd"]
}
Ac.items
Code: Select all
Group:Switch:OR(ON, OFF) gIrTX "All IR transmiters [%d]" <light>
Group:Switch:OR(ON, OFF) gIrTV "All IR TV transmiters [%d]" <screen>
Group:String gIrAC "All IR AC transmiters [%d]" <snow>
Group:String gAC "All AC In the House [%d]" <snow>
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]" <fan> (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" (gIrTX,gIrAC) ["Switchable"] {channel="mqtt:topic:LivingRoomNode1:cmd"} //put your cmd channel here
AC.rules
Code: Select all
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\":"+transform("MAP", "truefalse.map", power.state.toString)+",\"Opmode\":\""+mode.state+"\",\"Degrees\":"+temp.state+",\"Fanspeed\":\""+fan.state+"\",\"Swingv\":\""+swing.state+"\"}'")
]
end
AC.sitemap
Code: Select all
Switch item=LivingRoomNode_AC mappings=[OFF="OFF" , COLD="Cold", HOT="Hot"]
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"]
truefalse.map
Code: Select all
true=ON
false=OFF
ON=true
OFF=false
Re: Controlling AC throught Openhab and ESP Easy
Posted: 03 Dec 2021, 14:16
by jimmys01
My Updated config!!!
This is the MQTT2 binding configuration
AC.things
Code: Select all
Thing mqtt:topic:LivingRoomNode1 "Living Room Node" (mqtt:broker:myMQTTBroker) {
Channels:
Type string : cmd [commandTopic="ESP_Easy/LivingRoomNode1/cmd"]
}
Ac.items
Code: Select all
Group:Switch:OR(ON, OFF) gIrTX "All IR transmiters [%d]" <light>
Group:Switch:OR(ON, OFF) gIrTV "All IR TV transmiters [%d]" <screen>
Group:String gIrAC "All IR AC transmiters [%d]" <snow>
Group:String gAC "All AC In the House [%d]" <snow>
String LivingRoom_Protocol "COOLIX" (gAC) //put in the label the protocol name
String LivingRoom_CustomOffCmd "IRSEND,'{\"protocol\":\"COOLIX\",\"data\":\"0xB27BE0\",\"bits\":24}'" (gAC) //Put in Comments if not applicable
Switch LivingRoom_Power "Power" (gAC)
String LivingRoom_Mode "Mode" (gAC) // mode of operation - one of Auto/Dry/Cool/Heat/Fan/Night
String LivingRoom_Model "Model" "-1" (gAC) //default model is -1
Number LivingRoom_Temp "Temp [%.0f °C]" (gAC) // temperature set point
String LivingRoom_Fan "Fan" <fan> (gAC) // fan mode - one of Auto/F1/F2/F3/F4/F5
String LivingRoom_Swing "Swing" (gAC) // swing mode - one of Off/UpDown
String LivingRoom_IR "Living Room IR" (gIrTX,gIrAC) {channel="mqtt:topic:LivingRoomNode1:cmd"} //put your cmd channel here
AC.rules
[code]import org.openhab.core.model.script.ScriptServiceUtil
var Timer acCommandDelay = null
rule "AC state changed"
when
Member of gAC received command
then
//logInfo("AC", "------------"+triggeringItemName +" changed to " + triggeringItem.state)
var triggeringItem = ScriptServiceUtil.getItemRegistry.getItems(triggeringItemName).get(0);
var baseItemName= triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))
var protocol = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Protocol")]
var model = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Model")]
var customOffCommand = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_CustomOffCmd")]
var power = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Power")]
var mode = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Mode")]
var temp = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Temp")]
var fan = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Fan")]
var swing = gAC.members.findFirst[name.equals(triggeringItemName.substring(0,triggeringItemName.lastIndexOf("_"))+"_Swing")]
var light = "true"
var beep = "true"
//var turbo =
//val spower = transform("MAP", "truefalse.map", power.state.toString)
if (power.state===null||temp.state===null||fan.state===null||swing.state===null||protocol.label===null) {return}
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
if (power.state==ON || customOffCommand.label.toString()===null) //Check if we have a custom off command
sendCommand( baseItemName +"_IR", "IRSENDAC,'{\"Protocol\":\""+protocol.label+"\",\"Model\":"+model.label+",\"Power\":\""+power.state.toString()+"\",\"Mode\":\""+mode.state+"\",\"Temp\":"+temp.state+",\"Fanspeed\":\""+fan.state+"\",\"light\":\""+light+"\",\"beep\":\""+beep+"\"}'")
else //send custom off command that is not supported by the library
sendCommand( baseItemName +"_IR", customOffCommand.label.toString())
]
end
AC.sitemap
Code: Select all
Switch item=LivingRoomNode_AC mappings=[OFF="OFF" , COLD="Cold", HOT="Hot"]
Default item=LivingRoom_Power
Switch item=LivingRoom_Mode mappings=[cold="Cold" , heat="Heat", 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"]
truefalse.map
Code: Select all
true=ON
false=OFF
ON=true
OFF=false