For the wm_status i use .checkFirst() so the log of the divices show only state changes. How can i use that for the text switches so only the message is updated when there is an change. i got now a lot of log pages with the same state.
for the WM Klaar om i get "completionTime": {"value": "2020-02-18T19:40:06.568Z"} how can i translate that to 20:40 (1 hour offset and date is not relevant)?
From the json "data" i get
Code: Select all
"data": {
"value": "{\"payload\":{\"x.com.samsung.da.state\":\"Run\",\"x.com.samsung.da.delayEndTime\":\"00:00:00\",\"x.com.samsung.da.remainingTime\":\"01:35:00\",\"if\":[\"oic.if.baseline\",\"oic.if.a\"],\"x.com.samsung.da.progressPercentage\":\"53\",\"x.com.samsung.da.supportedProgress\":[\"None\",\"Weightsensing\",\"Wash\",\"Rinse\",\"Spin\",\"Finish\"],\"x.com.samsung.da.progress\":\"Wash\",\"rt\":[\"x.com.samsung.da.operation\"]}}"
},
Code: Select all
"washerSpinLevel": {
"value": "1400"
how can i get from data. The progressPerecentage and the remainingTime ?
Are there more sugestions to improve this script?
Code: Select all
-- assumpitions for Samsung Wasmachine Script
-- Dummy textdevices WM Programma, WM Klaar om, WM aan het, WM Toerental, WM Resterend, WM Temperatuus.
-- Dummy on/of switch WM Status
-- 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/
local API = '1234c-abcd-1234'
local Device = '987654321'
local LOGGING = true
-- Translate Washing courses to Language Text
local Course_D0 = 'Katoen'
local Course_D1 = 'Eco Katoen'
local Course_D2 = 'Syntethisch'
local Course_D3 = 'Fijne Was'
local Course_D4 = 'Spelen+Centrifugeren'
local Course_D5 = 'Eco Trommelreiniging'
local Course_D6 = 'Beddengoed'
local Course_D7 = 'Outdoor'
local Course_D8 = 'Wol'
local Course_D9 = 'Donkere Kleding'
local Course_DA = 'Super Ecowas'
local Course_DB = 'Super Speed'
local Course_DC = '15 min Kort'
local Course_BA = 'Centrifugeren'
local Machine_Off = 'Wasmachine uit'
--Define Domoticz Switches
local WM_STATUS = 'WM Status' --Domoitcz virtual switch ON/Off state Washer
return {
on = {
timer = {
'every 1 minutes' -- just an example to trigger the request
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
execute = function(domoticz, item, myDevice, triggerinfo)
local wm_status = domoticz.devices(WM_STATUS)
if (item.isTimer) then
domoticz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device .. '/states',
headers = { ['Authorization'] = 'Bearer'.. API },
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
local completionTime = item.json.main.completionTime.value -- Hot to translaten 2020-02-13T21:59:00.887Z to 21:59
local switch = item.json.main.switch.value
local washerWaterTemperature = item.json.main.washerWaterTemperature.value
local washerJobState = item.json.main.washerJobState.value
local washerMode = item.json.main.washerMode.value
local washerSpinLevel = item.json.main.washerSpinLevel.value
-- local remainingTime = item.json.main.data.value.payload -- How to get ?
if LOGGING then
domoticz.log('Debuggg switch:' .. switch, domoticz.LOG_INFO)
domoticz.log('Debuggg wm_status:' .. wm_status.state, domoticz.LOG_INFO)
end
-- if wm_status.state ~= ('Off') and switch ~= ('off') then --Prevents device changes (in the log) when washer is Off and status is already off.
if switch == ('on') then
wm_status.switchOn().checkFirst() --turn on domoitcz WM status switch
domoticz.devices('WM Temperatuur').updateText(washerWaterTemperature)
domoticz.devices('WM Aan het').updateText(washerJobState)
domoticz.devices('WM Toerental').updateText(washerSpinLevel)
-- domoticz.devices('WM Resterend').updateText(remainingTime)
domoticz.devices('WM Klaar om').updateText(completionTime)
if washerMode == ('Table_00_Course_D0')
then domoticz.devices('WM Programma').updateText(Course_D0)
elseif washerMode == ('Table_00_Course_D1')
then domoticz.devices('WM Programma').updateText(Course_D1)
elseif washerMode == ('Table_00_Course_D2')
then domoticz.devices('WM Programma').updateText(Course_D2)
elseif washerMode == ('Table_00_Course_D3')
then domoticz.devices('WM Programma').updateText(Course_D3)
elseif washerMode == ('Table_00_Course_D4')
then domoticz.devices('WM Programma').updateText(Course_D4)
elseif washerMode == ('Table_00_Course_D5')
then domoticz.devices('WM Programma').updateText(Course_D5)
elseif washerMode == ('Table_00_Course_D6')
then domoticz.devices('WM Programma').updateText(Course_D6)
elseif washerMode == ('Table_00_Course_D7')
then domoticz.devices('WM Programma').updateText(Course_D7)
elseif washerMode == ('Table_00_Course_D8')
then domoticz.devices('WM Programma').updateText(Course_D8)
elseif washerMode == ('Table_00_Course_D9')
then domoticz.devices('WM Programma').updateText(Course_D9)
elseif washerMode == ('Table_00_Course_DA')
then domoticz.devices('WM Programma').updateText(Course_DA)
elseif washerMode == ('Table_00_Course_DB')
then domoticz.devices('WM Programma').updateText(Course_DB)
elseif washerModee == ('Table_00_Course_DC')
then domoticz.devices('WM Programma').updateText(Course_DC)
elseif washerMode == ('Table_00_Course_BA')
then domoticz.devices('WM Programma').updateText(Course_BA) end
else
wm_status.switchOff().checkFirst()
domoticz.devices('WM Temperatuur').updateText(Machine_Off)
domoticz.devices('WM Aan het').updateText(Machine_Off)
domoticz.devices('WM Programma').updateText(Machine_Off)
domoticz.devices('WM Toerental').updateText(Machine_Off)
domoticz.devices('WM Resterend').updateText(Machine_Off)
domoticz.devices('WM Klaar om').updateText(Machine_Off)
end
--end
if LOGGING then
domoticz.log('Klaar om:' .. completionTime, domoticz.LOG_INFO)
domoticz.log('Status:' .. switch, domoticz.LOG_INFO)
domoticz.log('Temperatuur:' .. washerWaterTemperature, domoticz.LOG_INFO)
domoticz.log('Aan het:' .. washerJobState, domoticz.LOG_INFO)
domoticz.log('Programma:' .. washerMode, domoticz.LOG_INFO)
domoticz.log('Toerental:' .. washerSpinLevel, domoticz.LOG_INFO)
-- domoticz.log('Resterende tijd:' .. remainingTime, domoticz.LOG_INFO)
-- domoticz.log(domoticz.utils.fromJSON(item.data))
end
end
else
if LOGGING == true then
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
end
}