Samsung AirComditioner (2019) - Samsung Smart Things

Just did a quick example for humidity:

https://api.smartthings.com/v1/devices/deviceID/components/main/capabilities/relativeHumidityMeasurement/status

Gives me following output:

{
    "humidity": {
        "value": 52,
        "unit": "%",
        "timestamp": "2021-06-28T13:18:02.423Z"
    }
}

Cannot do a command right now as the aircon is in use, but will try tomorrow and report back.

1 Like

Did you run this command in Postman with GET?

And this was the output you received?

I tried to run the same command you shared as a GET command (with my deviceID), but I got this output:

{
    "humidity": {
        "value": 0,
        "unit": "%",
        "timestamp": "2021-06-28T13:59:03.453Z"
    }
}

Yes, GET URL. Your output seems to be correct, just that the humidity is currently measured with 0.
I assume your AC is turned on and humidity is not 0 though right? :slight_smile:

1 Like

Correct. My AC was on when I ran the GET URL, and humidity was most likely not 0 :slight_smile:
Maybe it takes a few minutes from the moment the AC powers ON till the humidity sensor takes a reading?

The humidity is not measured while using cool mode afaik. Try to switch to dry mode and run the command again.

1 Like

Okay guys here´s party three:

First install the EXEC binding in Openhab:

Also make sure to whitelist your Exec commands in the following file: (whitelist is an “old” version here - I ´m working with input arguments while using the python scripts already…)

image

I´m not 100% sure but I tried wildcards and it wasn´t working for me.

Next step is to create the exec binding things. I created 3 thinkgs for each AC unit.

One is checking the Power status. The other one´s are disabled (to reduce “noise” in my logging) and only gets activated if the AC unit is powered on.

I´m checking every 2 minutes if the device is ON.

If the AC unit is on - the “Status update” things gets active (through my rule) and then updates the temperature / operating mode status every 5 seconds.

EDIT: If you want to use python with input arguments (not having a script for setting temperature to 21 degree and another script to set the temperature to 22 degree) you can use the following example:

payload = "[{\"component\":\"main\",\"capability\":\"thermostatCoolingSetpoint\",\"command\":\"setCoolingSetpoint\",\"arguments\": ["+ temp +"]}]"

The argument will then be “filled” with the following example:

sudo python3 /home/exec/klima_eg_set_temperature.py 21.0

…as 21.0 is the input argument!

Next will be creating all the Items and finally the rules!

Last but not least: I know that my solution is (as I already mentioned) not state of the art and maybe the choice to use python (instead of http) is bad but for me it was easier to use as I was not able to use http binding with authorization bearer and so on…

Always open minded for tips / advices to improve my solution.

1 Like

You are correct. Under Dry mode the humidity status GET URL command works :pray:

Alright guys - here are my items for the AC units.

I simply linked the EXEC Thing channels to my items (most of it, some of them are only just holding status information):

//Aktualisiert den Status der Klimaanlage (ON = Abfrage läuft bei smartthings API, OFF = idle)
Switch                Klima_Essbereich_Switch_Akt          "Klima Essbereich aktualisieren"                                      {channel="exec:command:170d6e6a:run"}
Switch                Klima_Schlafzimmer_Switch_Akt        "Klima Schlafzimmer aktualisieren"                                    {channel="exec:command:a60269bec2:run"}
Switch                Klima_Kinderzimmer_Switch_Akt        "Klima Kinderzimmer aktualisieren"                                    {channel="exec:command:13d71ac329:run"}

//zeigt aktuellen Power Status an (on / off), Input kommt von smartthings API
String                Klima_Essbereich_Switch_Status       "Klima Essbereich"                                                    {channel="exec:command:170d6e6a:output"}
String                Klima_Schlafzimmer_Switch_Status     "Klima Schlafzimmer"                                                  {channel="exec:command:a60269bec2:output"}
String                Klima_Kinderzimmer_Switch_Status     "Klima Kinderzimmer"                                                  {channel="exec:command:13d71ac329:output"}

//zeigt/aktualisiert aktuellen Temperaturwert (Setpoint) vom Klimagerät an
Switch                Klima_Essbereich_Temp_Akt            "Klima Essbereich Temperatur aktualisieren"
String                Klima_Essbereich_Temp_Status         "Klima Essbereich Temperatur"
Switch                Klima_Schlafzimmer_Temp_Akt          "Klima Schlafzimmer Temperatur aktualisieren"                         {channel="exec:command:66af9ff7ee:run"}
String                Klima_Schlafzimmer_Temp_Status       "Klima Schlafzimmer Temperatur"                                       {channel="exec:command:66af9ff7ee:output"}
Switch                Klima_Kinderzimmer_Temp_Akt          "Klima Kinderzimmer Temperatur aktualisieren"                         {channel="exec:command:22e78796b8:run"}
String                Klima_Kinderzimmer_Temp_Status       "Klima Kinderzimmer Temperatur"                                       {channel="exec:command:22e78796b8:output"}

//zeigt/aktualisiert aktuellen Kühlmodus an (Fast, Windfree, Normal, ...)
Switch                Klima_Essbereich_Op_Mode_Akt         "Klima Essbereich Operating Mode aktualisieren"
String                Klima_Essbereeich_Op_Mode_Status     "Klima Essbereich Operating Mode"
Switch                Klima_Schlafzimmer_Op_Mode_Akt       "Klima Schlafzimmer Operating Mode aktualisieren"                     {channel="exec:command:0d945c8ca4:run"}
String                Klima_Schlafzimmer_Op_Mode_Status    "Klima Schlafzimmer Operating Mode"                                   {channel="exec:command:0d945c8ca4:output"}
Switch                Klima_Kinderzimmer_Op_Mode_Akt       "Klima Kinderzimmer Operating Mode aktualisieren"                     {channel="exec:command:0c5415beb6:run"}
String                Klima_Kinderzimmer_Op_Mode_Status    "Klima Kinderzimmer Operating Mode"                                   {channel="exec:command:0c5415beb6:output"}

//Power Switches
Switch                Klima_EG_Switch                      "Klima EG"
String                Klima_EG_Temp                        "Klima EG Temperatur %s"                             <temperature>
Switch                Klima_SZ_Switch                      "Klima SZ"
String                Klima_SZ_Temp                        "Klima SZ Temperatur %s"                             <temperature>
Switch                Klima_KZ_Switch                      "Klima KZ"
String                Klima_KZ_Temp                        "Klima KZ Temperatur %s"                             <temperature>

//Kühlmodus (Windfree, Normal, Windfreesleep,...)
Number                Klima_EG_Mode                        "Klima EG Modus"
Number                Klima_SZ_Mode                        "Klima SZ Modus"
Number                Klima_KZ_Mode                        "Klima KZ Modus"

//Setpoint per Sitemap für Ziel-Temperatur Einstellung
Number:Temperature    Klima_EG_Setpoint                    "Klima EG Setpoint [%.1f]"                           <temperature>
Number:Temperature    Klima_SZ_Setpoint                    "Klima SZ Setpoint [%.1f]"                           <temperature>
Number:Temperature    Klima_KZ_Setpoint                    "Klima SZ Setpoint [%.1f]"                           <temperature>

1 Like

Alright guys and finally here are my rules.

For setting the temperature I am not using the input argument of the python script anymore because I had problems with my rule and tried it this way. I need to change it back again as the issue was not from this lines of code.

Initially I wanted to use a hysterese to turn the AC units on & off but finally I´m using now the average temperature value of the last 45 minutes.
So variables are also available for hysterese - if you prefer it that way.

var Number setpoint_eg
var Number setpoint_kz
var Number setpoint_sz
var Number hysteresis_eg = 1
var Number hysteresis_sz = 1
var Number hysteresis_kz = 1
var String mode
val headers = newHashMap("Authorization" -> "Bearer oh.restapi.yourTOKENID", "WWW-Authenticate"-> "Basic")

//Klimaautomatik für das Erdgeschoss abhängig von aktueller Raumtemperatur und gesetztem Wert (Setpoint)
rule "Klimaanlage EG automatisch steuern"

when Item Temperatur_Wohnzimmer changed or
Item Klima_EG_Setpoint changed or
Item Klimaautomatik_EG changed or
Item Klimaautomatik changed 


then 

//Temperatur im EG auslesen
Temperatur_Wohnzimmer_Average.state = Temperatur_Wohnzimmer.averageSince(now.minusMinutes(45))
//Setpoint aus App auslesen
setpoint_eg = (Klima_EG_Setpoint.state as Number)
var temp_wohnzimmer_average = (Temperatur_Wohnzimmer_Average.state as Number)
var setpoint_eg_hyst = setpoint_eg

  logInfo("INFO","Wohnzimmer Durchschnitt letzte Stunde: " + temp_wohnzimmer_average)
  logInfo("INFO","Wohnzimmer Setpoint: " + setpoint_eg_hyst)
//wenn jemand zuhause ist, nicht geschlafen wird und die Klimaautomatik-Regel aktiviert ist dann schalte die Klimaanlage ein!
if (Home_Mode.state == ON && Sleep_Mode.state == OFF && Klimaautomatik.state == ON && Klimaautomatik_EG.state == ON) 
{
  
    if (temp_wohnzimmer_average >= setpoint_eg_hyst)
    {
            if (Klima_EG_Switch.state == OFF) {
            executeCommandLine("sudo", "python3", "/home/exec/klima_eg_power_switch.py")
            Thread::sleep(500)
            executeCommandLine("sudo", "python3", "/home/exec/klima_eg_cool_mode.py ")            
            Thread::sleep(500)
            executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py ")
            Thread::sleep(500)
            //Klima EG immer im Windfree Modus betreiben
            executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_operating_mode.py", "windFree")
            logInfo("INFO","Klima im EG wird aktiviert da es zu warm ist!")
            Klima_EG_Switch.sendCommand(ON)      
            Thread::sleep(300)
            Klima_EG_Temp.postUpdate(Klima_Essbereich_Temp_Status.state.toString.substring(28,32))             
            }
    }

else {

    if (Klima_EG_Switch.state == ON)   {
    executeCommandLine("sudo", "python3", "/home/exec/klima_eg_power_off_switch.py")
    logInfo("INFO","Klima im EG wird deaktiviert da Zieltemperatur erreicht!")
    Klima_EG_Switch.sendCommand(OFF)    
    }

}

}

end

//Klimaanlage ein- und ausschalten über Openhab (Swich = Power)
rule "Klimaanlage EG Switch"

when Item Klima_EG_Switch changed

then 

if (Klima_EG_Switch.state == ON) {

    executeCommandLine("sudo", "python3", "/home/exec/klima_eg_power_switch.py")
    Thread::sleep(500)
    executeCommandLine("sudo", "python3", "/home/exec/klima_eg_cool_mode.py ")
    
}

if (Klima_EG_Switch.state == OFF) {

    executeCommandLine("sudo", "python3", "/home/exec/klima_eg_power_off_switch.py")
    

}

end 

//Prüfen mit EXEC-Klima_EG_Power_Status_Abfrage in regelmäßigem Intervall ob Klima ggf. per Fernbedienung/App ein-/ausgeschalten wurde
rule "Check Klima EG Fernbedienung Power"

when Item Klima_Essbereich_Switch_Status changed 

then 


if (Klima_Essbereich_Switch_Status.state.toString.contains("off")) {

    Klima_EG_Switch.sendCommand(OFF)
    
}

else if (Klima_Essbereich_Switch_Status.state.toString.contains("on")) {

    Klima_EG_Switch.sendCommand(ON)
    

}

end 

//eingestellter Temperaturwert vom Klimagerät auslesen
rule "Check Klima EG Temperatur"

when Item Klima_Essbereich_Temp_Status changed or 
Item Klima_Essbereich_Temp_Akt changed

then 


Klima_EG_Temp.postUpdate(Klima_Essbereich_Temp_Status.state.toString.substring(28,32))


end

//Setpoint Temperatur an Klimaanlage EG übergeben
rule "Setpoint Temp an Klimaanlage EG uebergeben"

when Item Klima_EG_Setpoint changed 

then 

if (Klima_EG_Setpoint.state == 20.0 | °C || Klima_EG_Setpoint.state == 20.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"20.0")
}

if (Klima_EG_Setpoint.state == 21.0 | °C || Klima_EG_Setpoint.state == 21.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"21.0")
}

if (Klima_EG_Setpoint.state == 22.0 | °C || Klima_EG_Setpoint.state == 22.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"22.0")
}

if (Klima_EG_Setpoint.state == 23.0 | °C || Klima_EG_Setpoint.state == 23.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"23.0")
}

if (Klima_EG_Setpoint.state == 24.0 | °C || Klima_EG_Setpoint.state == 24.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"24.0")
}

if (Klima_EG_Setpoint.state == 25.0 | °C || Klima_EG_Setpoint.state == 25.5 | °C) {
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,"25.0")
}
//executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_temperature.py" ,Klima_EG_Setpoint.state.toString)
logInfo("INFO", "Klima EG Setpoint:" + Klima_EG_Setpoint.state.toString)

end

//eingestellter Kühlmodus vom Klimagerät auslesen
rule "Check Klima EG Mode"

when Item Klima_Essbereich_Op_Mode_Akt changed 

then 

var mode_eg = Klima_Essbereeich_Op_Mode_Status.state.toString.substring(154)

if (mode_eg.contains("off")) {

    Klima_EG_Mode.postUpdate(0)
}

if (mode_eg.contains("windFree")) {

    Klima_EG_Mode.postUpdate(1)
}

if (mode_eg.contains("speed")) {

    Klima_EG_Mode.postUpdate(2)
}

if (mode_eg.contains("windFreeSleep")) {

    Klima_EG_Mode.postUpdate(3)
}
end 


//Operating Mode an Klimaanlage von Openhab übergeben
rule "Operating Mode an Klimaanlage EG uebergeben"

when Item Klima_EG_Mode changed 

then 

if (Klima_EG_Mode.state == 0)
{
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_operating_mode.py", "off")

}

else if (Klima_EG_Mode.state == 1)
{
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_operating_mode.py", "windFree")

}

else if (Klima_EG_Mode.state == 2)
{
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_operating_mode.py", "speed")

}

else if (Klima_EG_Mode.state == 3)
{
executeCommandLine("sudo", "python3", "/home/exec/klima_eg_set_operating_mode.py", "windFreeSleep")

}
end

//Things Auto Status Update (Power, Mode, Temp) deaktivieren/aktivieren um unnötige Systemlast/Log Einträge zu verhindern
rule "Things Klima EG Status Update steuern"

when Item Klima_EG_Switch changed

then 

if (Klima_EG_Switch.state == ON) {

sendHttpPutRequest("http://192.168.1.199:8080/rest/things/exec%3Acommand%3Abccd4f91a7/enable", "application/json", 'true', headers, 1000)
sendHttpPutRequest("http://192.168.1.199:8080/rest/things/exec:command:141ebdc02b/enable", "application/json", 'true', headers, 1000)

}



if (Klima_EG_Switch.state == OFF) {

    sendHttpPutRequest("http://192.168.1.199:8080/rest/things/exec%3Acommand%3Abccd4f91a7/enable", "application/json", 'false', headers, 1000)
    sendHttpPutRequest("http://192.168.1.199:8080/rest/things/exec:command:141ebdc02b/enable", "application/json", 'false', headers, 1000)
}

end 
1 Like

Thank you, Mario, for taking the time to explain everything so thoroughly.
I will try to implement your method next week. I just hope it’s not too advance for my skills :pray::pray:

You´re welcome. Let me know if you are struggeling at some point.
Good luck! :wink:

1 Like

Thanks again, Mario :slight_smile:
Is it possible for you to share with us the parts in your Sitemap file that controls the AC’s?

Sure!

Text label="Klimaanlage" icon="klima" {
     Switch item=Klimaautomatik label="Klimaautomatik An/Aus" icon="klimaauto"
     Switch item=Klimaautomatik_EG label="Erdgeschoss Klimaautomat." icon="klimaauto"
     Switch item=Klimaautomatik_KZ label="Kinderzimmer Klimaautomat." icon="klimaauto"
     Switch item=Klimaautomatik_SZ label="Schlafzimmer Klimaautomat." icon="klimaauto"
     Switch item=Klima_EG_Switch label="Klima Erdgeschoss"
     Switch item=Klima_EG_Mode mappings=[0="Normal", 1="Windfree", 2="Fast", 3="WindfreeSleep"]
     Text item=Temperatur_Wohnzimmer label="Aktuelle Temperatur EG: [%.1f °C]"
     Text item=Klima_EG_Temp label="Eingestellte Temp. EG [%s °C]" icon="klimatemp"
     Setpoint item=Klima_EG_Setpoint label="Zieltemperatur EG [%.1f °C]" step=0.5 icon="targettemp"
     Switch item=Klima_SZ_Switch label="Klima Schlafzimmer"
     Switch item=Klima_SZ_Mode mappings=[0="Normal", 1="Windfree", 2="Fast", 3="WindfreeSleep"]
     Text item=Temperatur_Schlafzimmer label="Aktuelle Temperatur SZ: [%.1f °C]"
     Text item=Klima_SZ_Temp label="Eingestellte Temp. SZ [%s °C]" icon="klimatemp"
     Setpoint item=Klima_SZ_Setpoint label="Zieltemperatur SZ [%.1f °C]" step=0.5 icon="targettemp"
     Switch item=Klima_KZ_Switch label="Klima Kinderzimmer"
     Switch item=Klima_KZ_Mode mappings=[0="Normal", 1="Windfree", 2="Fast", 3="WindfreeSleep"]
     Text item=Shelly_Temperatur_Kinderzimmer label="Aktuelle Temperatur KZ: [%.1f °C]"
     Text item=Klima_KZ_Temp label="Eingestellte Temp. KZ [%s °C]" icon="klimatemp"
     Setpoint item=Klima_KZ_Setpoint label="Zieltemperatur KZ [%.1f °C]" step=0.5 icon="targettemp"

        }
1 Like

As always, thank you :slight_smile: :pray:

Hi friends,
I’m still struggling to find the proper POST commands to control all my Samsung AC’s capabilities/commands.

For example, I wasn’t able to find the right POST command to enable/disable the display light and all the other commands I mentioned in the quotes.

This is the list of components, capabilities, categories I got when I ran the GET function in Postman.
Could I trouble one of you to tell me how to find my missing POST commands? :pray: :pray:

"components": [
        {
            "id": "main",
            "capabilities": [
                {
                    "id": "ocf",
                    "version": 1
                },
                {
                    "id": "switch",
                    "version": 1
                },
                {
                    "id": "airConditionerMode",
                    "version": 1
                },
                {
                    "id": "airConditionerFanMode",
                    "version": 1
                },
                {
                    "id": "fanOscillationMode",
                    "version": 1
                },
                {
                    "id": "airQualitySensor",
                    "version": 1
                },
                {
                    "id": "temperatureMeasurement",
                    "version": 1
                },
                {
                    "id": "thermostatCoolingSetpoint",
                    "version": 1
                },
                {
                    "id": "relativeHumidityMeasurement",
                    "version": 1
                },
                {
                    "id": "dustSensor",
                    "version": 1
                },
                {
                    "id": "veryFineDustSensor",
                    "version": 1
                },
                {
                    "id": "audioVolume",
                    "version": 1
                },
                {
                    "id": "remoteControlStatus",
                    "version": 1
                },
                {
                    "id": "powerConsumptionReport",
                    "version": 1
                },
                {
                    "id": "demandResponseLoadControl",
                    "version": 1
                },
                {
                    "id": "refresh",
                    "version": 1
                },
                {
                    "id": "execute",
                    "version": 1
                },
                {
                    "id": "custom.spiMode",
                    "version": 1
                },
                {
                    "id": "custom.thermostatSetpointControl",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerOptionalMode",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerTropicalNightMode",
                    "version": 1
                },
                {
                    "id": "custom.autoCleaningMode",
                    "version": 1
                },
                {
                    "id": "custom.deviceReportStateConfiguration",
                    "version": 1
                },
                {
                    "id": "custom.energyType",
                    "version": 1
                },
                {
                    "id": "custom.dustFilter",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerOdorController",
                    "version": 1
                },
                {
                    "id": "custom.deodorFilter",
                    "version": 1
                },
                {
                    "id": "custom.disabledComponents",
                    "version": 1
                },
                {
                    "id": "custom.disabledCapabilities",
                    "version": 1
                },
                {
                    "id": "samsungce.driverVersion",
                    "version": 1
                }
            ],
            "categories": [
                {
                    "name": "AirConditioner",
                    "categoryType": "manufacturer"
                }
            ]
        },
        {
            "id": "1",
            "capabilities": [
                {
                    "id": "switch",
                    "version": 1
                },
                {
                    "id": "airConditionerMode",
                    "version": 1
                },
                {
                    "id": "airConditionerFanMode",
                    "version": 1
                },
                {
                    "id": "fanOscillationMode",
                    "version": 1
                },
                {
                    "id": "temperatureMeasurement",
                    "version": 1
                },
                {
                    "id": "thermostatCoolingSetpoint",
                    "version": 1
                },
                {
                    "id": "relativeHumidityMeasurement",
                    "version": 1
                },
                {
                    "id": "airQualitySensor",
                    "version": 1
                },
                {
                    "id": "dustSensor",
                    "version": 1
                },
                {
                    "id": "veryFineDustSensor",
                    "version": 1
                },
                {
                    "id": "odorSensor",
                    "version": 1
                },
                {
                    "id": "remoteControlStatus",
                    "version": 1
                },
                {
                    "id": "audioVolume",
                    "version": 1
                },
                {
                    "id": "custom.thermostatSetpointControl",
                    "version": 1
                },
                {
                    "id": "custom.autoCleaningMode",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerTropicalNightMode",
                    "version": 1
                },
                {
                    "id": "custom.disabledCapabilities",
                    "version": 1
                },
                {
                    "id": "ocf",
                    "version": 1
                },
                {
                    "id": "powerConsumptionReport",
                    "version": 1
                },
                {
                    "id": "demandResponseLoadControl",
                    "version": 1
                },
                {
                    "id": "custom.spiMode",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerOptionalMode",
                    "version": 1
                },
                {
                    "id": "custom.deviceReportStateConfiguration",
                    "version": 1
                },
                {
                    "id": "custom.energyType",
                    "version": 1
                },
                {
                    "id": "custom.dustFilter",
                    "version": 1
                },
                {
                    "id": "custom.airConditionerOdorController",
                    "version": 1
                },
                {
                    "id": "custom.deodorFilter",
                    "version": 1
                }
            ],
            "categories": [
                {
                    "name": "Other",
                    "categoryType": "manufacturer"

Hi @Mario084 , since I’m not a developer and I don’t fully understand your process, I tried to copy your method exactly, while substituting your Device ID’s with my own Samsung AC’s device id’s to create the GET and POST commands, and by substituting your Things identifiers with the ones my OpenHAB system created in the Items file.
Unfortunately, I must have done something wrong, because when I tried to press the new AC’s buttons in my sitemap they did not change any settings on my AC’s.
I must be doing something wrong :frowning:

Hi @Mario084 and @mjeshurun,
Just to report back on progress as I am investing some time today.
Below an example using the HTTP binding and “GET”'ing the AC status:

HTTP Thing Definition

Replace the black bars with your deviceID and token.


Channel

Item

Channel & Item is pretty straight forward.

At the same time I am also trying to get this working only with ECMA scripts and the HTTPUtil, whereas I still did not figure out the correct syntax I think:

ECMA test code

//Initialize variables

var telegramAction = actions.get(“telegram”,“telegram:telegramBot:telegram”);
var Log = Java.type(“org.openhab.core.model.script.actions.Log”);
var ZonedDateTime = Java.type(“java.time.ZonedDateTime”);
var ScriptExecution = Java.type(“org.openhab.core.model.script.actions.ScriptExecution”);
var HttpUtil = Java.type(“org.openhab.core.io.net.http.HttpUtil”);

var timeofday = itemRegistry.getItem(“ntp_timeofday”).getState ();
var homestatus = itemRegistry.getItem(“presence_home”).getState ();
var presence = itemRegistry.getItem(“presence_bedroom_master”).getState ();
var scene = itemRegistry.getItem(“scene_bedroom_master”).getState ();

var headers = new testProperty();
headers.put(“Authorization”,“Bearer TOKEN”);

//Actions

HttpUtil.executeUrl(“POST”, “https://api.smartthings.com/v1/devices/ID/commands”, headers,“application/JSON”, { “component”: “main”, “capability”: “switch”, “command”: “off” });

ECMA test code Try 2

var token = “TOKEN”

var headers = ;
headers[“Authorization”] = "Bearer " + token;

var url = “https://api.smartthings.com/v1/devices/ID/commands”;
var jsondata = ‘{“component”: “main”, “capability”: “switch”, “command”: “on”}’;
var result = HTTP.sendHttpPostRequest(url, “application/json”, jsondata, headers,15000);

ECMA test code Try 3 - **WORKING**

var token = “TOKEN”

var headers = ;
headers[“Authorization”] = "Bearer " + token;

var url = “https://api.smartthings.com/v1/devices/ID/commands”;
var jsondata = ‘[{“component”: “main”, “capability”: “switch”, “command”: “off”}]’;
var result = HTTP.sendHttpPostRequest(url, “application/json”, jsondata, headers,15000);

If anyone got some pointers there, appreciated.
Hope above helps a bit for standard setup, will try another one with command channel next.

EDIT2: Added ECMA test code 2 which gives me no log errors but also does not send the command :frowning:

EDIT3: Got it working with simple POST code!! (see ECMA test code Try 3)
EDIT4: Now also implemented 2 rules to turn off/on the AC which works - still trouble getting it into one rule, but that’s more of an OH rule thing that I need to figure out (brain freeze :slight_smile: )

EDIT 5: OK, made some progress, I got the following GETs running, in case you want to have the GET URLs, let me know:

image

Looking at your list of capabilities (which btw is exactly the same that I got) it seems that you cannot control the light via the REST API. Might be wrong here as in the app you got options like “Lighting” and “Sound Effects”, maybe they are not exposed via capabilities?

1 Like

Thank you for taking the time to look into my question :pray:
And thank you for taking the time to describe your HTTP solution.
As I’m a noob in these matters, I would appreciate if you could share the GET/POST URL’s and POST commands you used.
Also, if there is no privacy issue, could you share your Things, Items, Rules and Sitemap settings?
I’m hoping that by having your initial definitions, I could just enter my Samsung AC’s Device ID’s and Token Bearer, thus making your definitions work for my devices :pray: :pray: :pray:

Hi @mjeshurun, please see below, I hope they help:

Thing:


2 Channel Examples (the concept is the same for all of them):

On/Off:


Set Temperature:

Item Example:

image

My On/Off rules (currently 2 rules, not sure why my if, else is not working if combined:)

Turn On:


Turn Off:


The GET codes I currently implemented, the POST code (on/off) is visible in above rule, I did not implement any more yet:

Stats - On/Off: https://api.smartthings.com/v1/devices/ID/components/main/capabilities/switch/status
Set Temp: 
https://api.smartthings.com/v1/devices/ID/components/main/capabilities/thermostatCoolingSetpoint/status
AC Mode: https://api.smartthings.com/v1/devices/ID/components/main/capabilities/custom.airConditionerOptionalMode/status
AirQuality: https://api.smartthings.com/v1/devices/ID/components/main/capabilities/airQualitySensor/status
Humidity:
https://api.smartthings.com/v1/devices/ID/components/main/capabilities/relativeHumidityMeasurement/status
Room Temp:
https://api.smartthings.com/v1/devices/ID/components/main/capabilities/temperatureMeasurement/status
AC Fan Mode:
https://api.smartthings.com/v1/devices/ID/components/main/capabilities/airConditionerFanMode/status

A thing I saw though is that the values in OH did not auto update, because the SmartThings APP did not auto refresh somehow. I had to open the app and refresh so that the AC is shown as turned on. Did you experience something similar @Mario084? Or Is there a setting to turn on auto refresh? (seems it worked over night, maybe just a Wifi drop-out)

1 Like