Trying to send Variable Command in Rules for A/C Remote Control with Tasmota-ir

Hello People. I have some NOOB and very beginner question.
I’m using Tasmota-ir and flashed it into Eachen IR device to control my SAMSUNG AirConditioner via OpenHAB and MQTT. Everything works fine.

The command can be sent directly via IRhvac command.
But I notice that
If we send command like:

IRHvac {"Vendor":"SAMSUNG_AC", "Power":"On"}

The actual command to A/C will be like this:

stat/tasmota_6E7106/RESULT = {"IRHVAC":{"Vendor":"SAMSUNG_AC","Model":1,"Mode":"Auto","Power":"On","Celsius":"On","Temp":21,"FanSpeed":"Medium","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"Off","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}

Also. If I didn’t specify parameter into it. Command will be sent like a default value let’s say
If I send

IRHvac {"Vendor":"SAMSUNG_AC", "Power":"On", "Temp":25}

sent command will be

stat/tasmota_6E7106/RESULT = {"IRHVAC":{"Vendor":"SAMSUNG_AC","Model":1,"Mode":"Auto","Power":"On","Celsius":"On","Temp":25,"FanSpeed":"Medium","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"Off","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}

If I sent

IRHvac {"Vendor":"SAMSUNG_AC", "Power":"On", "Mode":"Cool"}

sent command will be

stat/tasmota_6E7106/RESULT = {"IRHVAC":{"Vendor":"SAMSUNG_AC","Model":1,"Mode":"Cool","Power":"On","Celsius":"On","Temp":21,"FanSpeed":"Medium","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"Off","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}

ํYou will notice that temperature is sent 21. Instead of 25
Meaning that IRHVAC will send all lump default of parameter. That’s a problem when I need to map it to openhab

Why? Because let’s say If you have On Off Button,Temp Selection and Mode selection
If I change Temp to 25, then set mode “Cool”. Temp will change back to 21.
Likewise. If set temp back to 25. Mode will change to the default “Auto”.

So I have an idea that if we can use rules to send the lump of command but command can be vary with an openhab input in example

val actions = getActions("mqtt","mqtt:broker:MosquittoMqttBroker")
    actions.publishMQTT("cmnd/tasmota_6E7106/IRhvac"," {\"Vendor\":\"<string variable>",\"Model\":<number variable>,\"Power\":\"<string variable>",\"Mode\":\"<string variable>",\"Celsius\":\"<string variable>\",\"Temp\":<Number variable>,\"FanSpeed\":\"<string variable>\",\"SwingV\":\"<string variable>\",\"SwingH\":\"<string variable>\",\"Quiet\":\"<string variable>\",\"Turbo\":\"<string variable>\",\"Econo\":\"<string variable>\",\"Light\":\"<string variable>\",\"Filter\":\"<string variable>",\"Clean\":\"<string variable>\",\"Beep\":\"<string variable>\",\"Sleep\":<number variable>} ")

It’s like that if we can get latest parameter into variable. So the command can sent with lump of parameter that memorize the latest another parameter.

Or if it cannot. I have to create a many rule to done this openhab A/C remote. That’s terrible.

I try hard to explain but I know that may hard to understand. haha. But hope someone can help me.

Or if anyone have the better idea than this and your idea is already worked. Please share to NOOB like me.

I also have the idea to make a universal remote in my openhab like you can select list of model. Meaning you can use openhab to command any of A/C that usable with IR Command libraly that refer to this link:
https://tasmota.github.io/docs/Tasmota-IR/

I think you might mean something like -

val my output = "Some output string" + some_Calculated_Variable.toString + "more string" + someItem.state.toString + "end string"
actions.publishMQTT("cmnd/tasmota_6E7106/IRhvac", output)

or

myCommandMQTTItem.sendCommand(output)

As I said that Im beginner. Can you explain that how is this code working? :joy:

Do you have an example?

When you are dealing with character strings, + just means join them together.

var x = "fred" + "mary" // result "fredmary"
var y =  2 + 2
x = x + y.toString  // result "fredmary4"
x = "elephant " + x + mySwitchItem.state.toString
// result "elephant fredmary4ON"

So, in a rule, you can gather different bits of data either from calculations in the rule or from other Items in your system, and stick them together in one bundle.

Thanks bro.
This one help me a lot. I’ll try it at my home.

Are you going to be using the remotes that come with the aircons?

Hi denominator

I dont understand your question. I just want openhab able to command to A/C like a remote that come with A/C

I have tried this rules


rule "Send Command to Aircon through IRBLASTER"
when

    Item AirconditionerPower received command or
    Item AirconditionerSetTemp received command or
    Item AirconditionerSetMode received command
then
        val mqttActions = getActions("mqtt","mqtt:broker:myMQTTBroker")
        var int setTemp = (AirconditionerSetTemp.state as Number).intValue
        var jsonString = '{"Vendor":"GREE","Model":1,' + 
                         '"Power":"'+ AirconditionerPower.state.toString +'",' +
                         '"Mode":"'+ AirconditionerSetMode.state.toString +'",' +
                         '"Celsius":"On",' +
                         '"Temp":'+ setTemp +',' +
                         '"FanSpeed":"Auto",' +
                         '"SwingV":"Auto",' +
                         '"SwingH":"Off",' +
                         '"Quiet":"Off",' +
                         '"Turbo":"Off",' +
                         '"Econo":"Off",' +
                         '"Light":"On",' +
                         '"Clean":"Off",' +
                         '"Filter":"Off",' +
                         '"Beep":"Off",' +
                         '"Sleep":-1}'
        logInfo("IRhvac", " Aircon To " + jsonString )    
        mqttActions.publishMQTT("irBlaster2/cmnd/IRhvac",  jsonString )         
        
end

rule "If google control tuning aircon on/off"
when
   Item AirconditionerMode received command
then

          if (receivedCommand != OFF){ 
            AirconditionerPower.sendCommand(ON)
            AirconditionerSetMode.sendCommand(receivedCommand)
            
            } else {
                      AirconditionerPower.sendCommand(OFF)
                   }

end

In frontail I can see the command is published. But looks like these commands not reaching to my tasmota-ir device

I also have a doubt with


logInfo("IRhvac", " Aircon To " + jsonString )    

What does ‘Aircon To’ stand for? It publish it and it is shown IRhvac Aircon To {jsoncommand}.

I also try to use

loginfo(“IRhvac”, jsonString)

It’s shown IRhvac {jsonString)
But tasmota-ir device still not get it.

MQTT already enable in tasmota-ir
MQTT things in openhab also online

It is very different if you want to track your remotes.

Ok so you are a very beginner that is copy pasting code that is not working :slight_smile: fun.

In my example I was using google voice assistant to control so I needed to handle the integration in a specific way.

This is just a message you can send to a logfile so you can see what is going on.

The “Aircon To” is just what I want the aircon to be set to, its just a message in the logfile that is all.
Front tail only shows what you tell it to and this is telling it to write what is in the jsonString variable to log file. This shows that the json string is formatted correctly.

As two systems are never the same use my example as a experts tutorial and with no explanation its not for beginners to be able to understand.

So now I hope you understand that its not the whole picture.


First you say you got it working on the tasmota console with

Awesome you got it to work.

Now read all tasmota docs and you will likely pull your hair out.

This tells me the format of your topics.

Can you install my favourite MQTT tool http://mqtt-explorer.com/ connect it to your broker as a tool to be able to look at what is happening inside MQTT

Now what are your items associated with this device?

Something like but can be anything…

Switch AirconditionerPower
Number AirconditionerSetTemp
String AirconditionerSetMode 

What is your openHAB MQTT Broker name ?

I think it is mqtt:broker:MosquittoMqttBroker from your first post but may be different.
In the example mine is mqtt:broker:myMQTTBroker

What editor are you using to change your rule files?

I use VSCode with openHAB extention.

Ok now we change this rule to suit your needs.

rule "Send Command to Aircon through IRBLASTER"
when

    Item AirconditionerPower received command or
    Item AirconditionerSetTemp received command or
    Item AirconditionerSetMode received command
then
        val mqttActions = getActions("mqtt","mqtt:broker:myMQTTBroker")
        var int setTemp = (AirconditionerSetTemp.state as Number).intValue
        var jsonString = '{"Vendor":"SAMSUNG_AC","Model":1,' + 
                         '"Power":"'+ AirconditionerPower.state.toString +'",' +
                         '"Mode":"'+ AirconditionerSetMode.state.toString +'",' +
                         '"Celsius":"On",' +
                         '"Temp":'+ setTemp +',' +
                         '"FanSpeed":"Auto",' +
                         '"SwingV":"Auto",' +
                         '"SwingH":"Off",' +
                         '"Quiet":"Off",' +
                         '"Turbo":"Off",' +
                         '"Econo":"Off",' +
                         '"Light":"On",' +
                         '"Clean":"Off",' +
                         '"Filter":"Off",' +
                         '"Beep":"Off",' +
                         '"Sleep":-1}'
        logInfo("IRhvac", " Aircon To " + jsonString )    
        mqttActions.publishMQTT("cmnd/tasmota_6E7106/IRhvac",  jsonString )         
        
end

Now you should be able to control the power set temp and mode. You can add to it to be able to change more settings if you want.

Ok in MQTT Explorer to the
topic cmnd/tasmota_6E7106/IRhvac
publish {"Vendor":"SAMSUNG_AC", "Power":"ON"}
This should work and be able to control your devices.

Hello Denominator

From MQTT explorer. When I send command from OpenHAB. I notice that jsonstring is published:

cmnd/tasmota_6E706/IRhvac = {jsonstring}

I tried to copy this and command via tasmota-ir directly. and got “Invalid JSON string”.

Then I tried to delete “=” and publish via tasmota-ir again

cmnd/tasmota_6E706/IRhvac  {jsonstring}

and it’s worked.

So. I don’t know how to make it publish without “=”

or you have any advise what am i missing?

What version of openHAB are you using?

What firmware of tasmota are you using?

What IR blaster did you flash?

In Tasmota console can you enter Status 0 and share what you get?

In MQTTE if you see the = sign its just mqtte adding it in.

image

You should be able to command your item in openHAB and then see the result in the Tasmota console.

The result with the temp 25 is from openHAB rule

This was setup in my openHAB 3 test instance.

triggers:
  - id: "1"
    configuration:
      itemName: AirconditionerPower
    type: core.ItemCommandTrigger
  - id: "2"
    configuration:
      itemName: AirconditionerSetMode
    type: core.ItemCommandTrigger
  - id: "3"
    configuration:
      itemName: AirconditionerSetTemp
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "4"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >-
        val mqttActions = getActions("mqtt","mqtt:broker:myMQTTBroker")

        // var int setTemp = (AirconditionerSetTemp.state as Number).intValue

        var setTemp = 25

        var jsonString = '{"Vendor":"SAMSUNG_AC","Model":1,' + 
                         '"Power":"'+ AirconditionerPower.state.toString +'",' +
                         '"Mode":"'+ AirconditionerSetMode.state.toString +'",' +
                         '"Celsius":"On",' +
                         '"Temp":'+ setTemp +',' +
                         '"FanSpeed":"Auto",' +
                         '"SwingV":"Auto",' +
                         '"SwingH":"Off",' +
                         '"Quiet":"Off",' +
                         '"Turbo":"Off",' +
                         '"Econo":"Off",' +
                         '"Light":"On",' +
                         '"Clean":"Off",' +
                         '"Filter":"Off",' +
                         '"Beep":"Off",' +
                         '"Sleep":-1}'
                logInfo("IRhvac", " Aircon To " + jsonString )    
                mqttActions.publishMQTT("cmnd/tasmota_6E7106/IRhvac",  jsonString ) 
    type: script.ScriptAction

It’s OpenHAB 3

tasmota-ir

Eachen IR DC6 IR Bridge Template for Tasmota (blakadder.com)

12:14:08 CMD: status 0
12:14:08 MQT: stat/tasmota_6E7106/STATUS = {"Status":{"Module":0,"DeviceName":"Tasmota","FriendlyName":["Tasmota"],"Topic":"tasmota_6E7106","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:10:32","StartupUTC":"2021-02-11T11:03:36","Sleep":50,"CfgHolder":4617,"BootCount":17,"BCResetTime":"2021-02-03T13:59:17","SaveCount":47,"SaveAddress":"F5000"}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS2 = {"StatusFWR":{"Version":"9.2.0(ir)","BuildDateTime":"2020-12-21T15:05:45","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8266EX","CR":"428/699"}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["lnwWiFi_2.4G","saramaclash_2.4G"],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C8000100060000005A00000000000000","00000100","00006000","00000000"]}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS4 = {"StatusMEM":{"ProgramSize":576,"Free":424,"Heap":23,"ProgramFlashSize":2048,"FlashSize":2048,"FlashChipId":"1540C8","FlashFrequency":40,"FlashMode":3,"Features":["00000809","0F5A0582","04000001","00000002","00000000","00000000","00000000","00000000"],"Drivers":"1,2,4,5,7,9,10,12","Sensors":""}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS5 = {"StatusNET":{"Hostname":"tasmota_6E7106-4358","IPAddress":"192.168.1.101","Gateway":"192.168.1.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.1","Mac":"2C:F4:32:6E:71:06","Webserver":2,"WifiConfig":4,"WifiPower":17.0}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.1.103","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_6E7106","MqttUser":"openhabian","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS7 = {"StatusTIM":{"UTC":"2021-02-11T11:14:08","Local":"2021-02-11T12:14:08","StartDST":"2021-03-28T02:00:00","EndDST":"2021-10-31T03:00:00","Timezone":"+01:00","Sunrise":"08:04","Sunset":"18:03"}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS10 = {"StatusSNS":{"Time":"2021-02-11T12:14:08"}}
12:14:08 MQT: stat/tasmota_6E7106/STATUS11 = {"StatusSTS":{"Time":"2021-02-11T12:14:08","Uptime":"0T00:10:32","UptimeSec":632,"Vcc":3.458,"Heap":23,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"Wifi":{"AP":1,"SSId":"lnwWiFi_2.4G","BSSId":"B0:BE:76:F2:22:02","Channel":3,"RSSI":76,"Signal":-62,"LinkCount":1,"Downtime":"0T00:00:03"}}}

This from my MQTTE when I click AC ON in my BasicUI

This cmnd topic appear suddenly when I click to command from my BasicUI
But in Tasmota console there is nothing happen

What I’m already did:
I just copy json payload from MQTTE (I don’t know I call it correctly or not lol). and deleted “=” as I told you guy then put in directly into tasmota console

IRHvac  {"Vendor":"SAMSUNG_AC","Model":1,"Power":"ON","Mode":"Auto","Celsius":"On","Temp":26,"FanSpeed":"Medium","SwingV":"Auto","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Clean":"Off","Filter":"Off","Beep":"Off","Sleep":-1}

and Yes. I can hear “Beep Beep” Sounds from my aircon

12:22:02 MQT: stat/tasmota_6E7106/RESULT = {"IRHVAC":{"Vendor":"SAMSUNG_AC","Model":1,"Mode":"Auto","Power":"On","Celsius":"On","Temp":26,"FanSpeed":"Medium","SwingV":"Auto","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}

Below is my rules (That I adapted from your code. Anyway, Not just copy and pasted I can say lol)

rule "Send Command to Aircon"
when

    Item AirconditionerSetPower received command or
    Item AirconditionerSetTemp received command or
    Item AirconditionerSetMode received command or
    Item AircondotionerSetFanSpeed received command or
    Item AirconditionerSetSwingV received command or
    Item AirconditionerSetTurbo  received command
then
        val mqttActions = getActions("mqtt","mqtt:broker:MosquittoMqttBroker")
        var int setTemp = (AirconditionerSetTemp.state as Number).intValue
        var jsonString = '{"Vendor":"SAMSUNG_AC","Model":1,' + 
                         '"Power":"'+ AirconditionerSetPower.state.toString +'",' +
                         '"Mode":"'+ AirconditionerSetMode.state.toString +'",' +
                         '"Celsius":"On",' +
                         '"Temp":'+ setTemp +',' +
                         '"FanSpeed":"Medium",' + 
                         '"SwingV":"Auto",' +
                         '"SwingH":"Off",' +
                         '"Quiet":"Off",' +
                         '"Turbo":"Off",' +
                         '"Econo":"Off",' +
                         '"Light":"On",' +
                         '"Clean":"Off",' +
                         '"Filter":"Off",' +
                         '"Beep":"Off",' +
                         '"Sleep":-1}'
        logInfo("IRhvac", " Aircon To " + jsonString )    
        mqttActions.publishMQTT("/cmnd/tasmota_6E7106/IRHvac", jsonString )         
        
end

This my items:

String AirconditionerSetPower            "AC ON/OFF []"    (Bedroom1, Aircon)  {channel="mqtt:topic:bedroom1ac:AirconPower"}
Number AirconditionerSetTemp "Temperature"  (Bedroom1, Aircon)  {channel="mqtt:topic:bedroom1ac:AirconTemp"}
String AirconditionerSetMode    "Mode" (Bedroom1, Aircon) {channel="mqtt:topic:bedroom1ac:AirconMode"}
String AirconditionerSetFanSpeed "FanSpeed" (Bedroom1, Aircon) {channel="mqtt:topic:bedroom1ac:AirconFanSpeed"}
String AirconditionerSetSwingV  "Swing" (Bedroom1, Aircon) {channel="mqtt:topic:bedroom1ac:AirconSwingV"}
Switch AirconditionerSetTurbo    "Turbo" (Bedroom1, Aircon) {channel="mqtt:topic:bedroom1ac:AirconTurbo"}

This is my things:

Thing mqtt:topic:bedroom1ac "Bedroom1 Air Conditioner" (mqtt:broker:MosquittoMqttBroker) {

Type	switch :	AirconPower		[stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"Power\".*)∩JSONPATH:$.IRHVAC.Power"]	
               //commandTopic = "cmnd/tasmota_6E7106/IRhvac" ]
Type	number :	AirconTemp		[stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"Temp\".*)∩JSONPATH:$.IRHVAC.Temp"]
               //commandTopic = "cmnd/tasmota_E304CB/ZbSend",  formatBeforePublish = "{ \"device\":\"LIVINGROOM1GLEDOPTO1\", \"send\":{\"Hue\":\"%s\"}}", min = "0", max = "254"]
Type	string :	AirconMode		[stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"Mode\".*)∩JSONPATH:$.IRHVAC.Mode"]
               //commandTopic = "cmnd/tasmota_E304CB/ZbSend",  formatBeforePublish = "{ \"device\":\"LIVINGROOM1GLEDOPTO1\", \"send\":{\"Sat\":\"%s\"}}", min = "0", max = "254"]
Type  string : AirconFanSpeed  [stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"FanSpeed\".*)∩JSONPATH:$.IRHVAC.FanSpeed"]	
               //commandTopic = "cmnd/tasmota_E304CB/ZbSend",  formatBeforePublish = "{ \"device\":\"LIVINGROOM1GLEDOPTO1\", \"send\":{\"Dimmer\":\"%s\"}}", min = "0", max = "254" ]               
Type  string : AirconSwingV  [stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"SwingV\".*)∩JSONPATH:$.IRHVAC.SwingV"]
               //commandTopic = "cmnd/tasmota_E304CB/ZbSend",  formatBeforePublish = "{ \"device\":\"LIVINGROOM1GLEDOPTO1\", \"send\":{\"Dimmer\":\"%s\"}}", min = "0", max = "254" ]   
Type  switch : AirconTurbo [stateTopic = "stat/tasmota_6E7106/RESULT" , transformationPattern = "REGEX:(.*\"Turbo\".*)∩JSONPATH:$.IRHVAC.Turbo"]
}

I have // comment because I modified from my rgb strip thing but no need to command via things channel. I think if we command from rules in will publish directly to pointed mqttbroker. So I just add channel to get the result state.

I think OpenHAB and tasmota already connected to mqtt broker already from the picture above. But wonder why Tasmota not received this mqtt message
Note: 192.168.1.103 is my openhabiandevice with port 1883 to MosquittoMqttBroker

Thankyou thankyou thankyou for providing such detailed information

:innocent:

This helps to take a detailed look as to the problem you have with your system it is a typo. You have now progressed to regular user and can no longer call yourself a NOOB.

the typo is / before cmnd in the rule

It changes the topic so tasmota doesn’t see it

image

It has been a pleasure helping you as you have put considerable effort in to get it working on your own and giving us enough detail to help you.

1 Like

Ahhhhhhhhhhhhhhhhhhh…

It’s true.
That’s why I need to asked openhab community :rofl:
Thank you so much for your help.

After deleted / before cmnd in the rules. I can hear “Beep Beep” Sound from my A/C right now.

Fantastic!!

This taught me I shouldn’t carelessly post any question. It can make a bigger trouble not only me. But for the people that come to give a hands.

Apologize for that.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.