Thank you very much. Now it is working!
This is the code that is working, is there any way to make them more organized?
Code: Select all
-- Assumpitions for Samsung Air Conditionner Script
-- API key from https://developer.samsung.com/smartthings
-- Device ID from https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/getDevices i used postman to get the device. Making a get requrdy with https://api.smartthings.com/v1/devices/
-- With method = 'POST' to work with the following commands:
--
--(Switch on): postData = '{"commands":[{"component":"main","capability":"switch","command":"on","arguments":[]}]}'
--(Switch off): postData = '{"commands":[{"component":"main","capability":"switch","command":"off","arguments":[]}]}'
--(Display off):postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.options":["Light_On"]}]}]}'
--(Heat): postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.modes":["Heat"]}]}]}'
--(Cool): postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.modes":["Cool"]}]}]}'
--(Setpoint): postData = '{"commands":[{"component":"main","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[26]}]}'
--(Quiet): postData = '{"commands":[{"component":"main","capability":"custom.airConditionerOptionalMode","command":"setAcOptionalMode","arguments":["quiet"]}]}'
-- With method = 'GET' the following url's:
--
--(Room Temp): url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/components/main/capabilities/temperatureMeasurement/status'
--(Humidity): url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/components/main/capabilities/relativeHumidityMeasurement/status'
--(Consumption):url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/components/main/capabilities/powerConsumptionReport/status'
-- https://community.home-assistant.io/t/samsung-air-conditioner/87046/55
local API = 'yyyyy'
local Device_1 = 'yyyyy' --Maria
local scriptVar = 'AC_Light_Off'
return {
active = function(domoticz) -- This function will be evaluated every minute by the dzVents system
myScript = domoticz.devices(592) -- This command checks the status of the switch to keep the script active
return myScript.state == "Off"
end,
on =
{
devices = {
AC_Maria,'AC Maria',
},
httpResponses =
{
scriptVar, -- must match with the callback passed to the openURL command
},
},
logging =
{
level = domoticz.LOG_DEBUG , -- set to LOG_ERROR when script works as expected or LOG_DEBUG for debugging
marker = scriptVar,
},
execute = function(dz, item)
local AC_Maria = dz.devices(589)
if dz.time.matchesRule('at 23:00-08:00') and AC_Maria.active then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
--callback = scriptVar, -- httpResponses above.
postData = '{"commands":[{"component":"main","capability":"switch","command":"on","arguments":[]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.modes":["Heat"]}]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{"commands":[{"component":"main","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[24]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.options":["Light_On"]}]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{"commands":[{"component":"main","capability":"custom.airConditionerOptionalMode","command":"setAcOptionalMode","arguments":["quiet"]}]}'
})
elseif item.isDevice and AC_Maria.active then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{"commands":[{"component":"main","capability":"switch","command":"on","arguments":[]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.modes":["Heat"]}]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{"commands":[{"component":"main","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[22]}]}'
})
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{ "commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0", {"x.com.samsung.da.options":["Light_On"]}]}]}'
})
elseif item.isDevice and AC_Maria.state == 'Off' then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device_1 .. '/commands',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'POST',
postData = '{"commands":[{"component":"main","capability":"switch","command":"off","arguments":[]}]}'
})
end
end
}
}