Hi all on this topic.
I have purchased two Samsung Washing machines which were installed yesterday (one dryer actually). I would like to thank anyone who contributed to these scripts. I have both the washing machine as the dryer working with similar scripts! Happy days....
Things I stumbled upon:
1. These are dzVents scripts, not bare lua
2. Dryer has completely different JSON structure, logging with the present logging feutures was not working so removed them competely
I have added some more translation stuff, and removed non-working logging rules as explained above.
I would like to share my contribution here, feel free to re-add the parts that you like!
I hope the isdst (Is Daylight Saving Time) implementation is working, so far it does on my setup.
Furthermore I changed the script so it should not crash when you add less dummy devices since you like to (untested).
P.s. I did a cleanup of the code structure, since, well, I am a software developer with some OCD
Code for the washing machine:
Code: Select all
-- SETUP YOUR API CONFIGURATION HERE --
-- API key from https://account.smartthings.com/tokens (You'll need to register first and ensure your machine is on the same account)
-- Device ID from https://graph-eu01-euwest1.api.smartthings.com/device/list (click on your machine, then use the number in the URL after the last /)
local API = 'GET YOUR API KEY FROM THE URL ABOVE'
local Device = 'GET YOUR DEVICE ID FROM THE URL ABOVE'
-- CREATE YOUR OWN OUTPUTS HERE --
-- Create virtual sensors in Domoticz Hardware settings that will show the output from the washing machine.
-- Names are suggested [in square brackets], you need to input the device ID in (brackets) below.
local WM_TEST_SWITCH = (200) -- Virtual on switch to activated the script manually for testing.
local WM_PROGRAM = (493) -- Virtual device showing washing machine Program [Washing - Device type = text
local WM_COMPLETION = (494) -- Virtual device showing washing cycle completion time - Device type = text
local WM_SPIN = (496) -- Virtual device showing washing spin state - Device type = text
local WM_REMAINING = (497) -- Virtual device showing time remaining on wash - Device type = text
local WM_TEMP = (498) -- Virtual device showing washing machine Temperature - Device type = text
local WM_STATUS = (499) -- Virtual device showing washing machine On/Off - Device type = on/off switch
local WM_PERCENT = (500) -- Virtual device showing washing machine percentage - Device type = percentage
local WM_STATE = (501) -- Virtual device showing washing cycle state - Device type = text
-- ------------------------
local scriptVar = 'WashingMachine'
local LOGGING = true
--Convert Table_00_Course_* and WashingState to English
local function codeToEnglish(dz, code)
local translationcode =
{
Table_00_Course_D0 = 'Cotton Wash',
Table_00_Course_D1 = 'Eco Cotton Wash',
Table_00_Course_D2 = 'Synthetics',
Table_00_Course_D3 = 'Delicates',
Table_00_Course_D4 = 'Rinse & Spin',
Table_00_Course_D5 = 'Drum Cleaning',
Table_00_Course_D6 = 'Bed Linnen',
Table_00_Course_D7 = 'Outdoor',
Table_00_Course_D8 = 'Wool',
Table_00_Course_D9 = 'Dark Wash',
Table_00_Course_DA = 'Super Eco Wash',
Table_00_Course_DB = 'Super Speed Wash',
Table_00_Course_DC = '15\' Quick Wash',
Table_00_Course_BA = 'Spin',
Table_02_Course_1B = 'Cotton',
Table_02_Course_1C = 'Eco 40-60',
Table_02_Course_1D = 'Super Speed Wash',
Table_02_Course_1E = '15\' Quick Wash',
Table_02_Course_1F = 'Intense Cold',
Table_02_Course_20 = 'Hygenic Steam',
Table_02_Course_21 = 'Colored Wash',
Table_02_Course_22 = 'Wool',
Table_02_Course_23 = 'Outdoor',
Table_02_Course_24 = 'Bed Linnen',
Table_02_Course_25 = 'Syntetic',
Table_02_Course_26 = 'Delicates',
Table_02_Course_27 = 'Rinse & Spin',
Table_02_Course_28 = 'Drain & Spin',
Table_02_Course_29 = 'Drum Cleaning',
Table_02_Course_2A = 'Jeans',
Table_02_Course_2B = 'All Wash',
Table_02_Course_2D = 'Silent Wash',
Table_02_Course_2E = 'Baby Clothes',
Table_02_Course_2F = 'Sportswear',
Table_02_Course_30 = 'Cloudy Day',
Table_02_Course_32 = 'Shirts',
Table_02_Course_33 = 'Towels',
none = 'Nothing',
weightSensing = 'Weight Sensing',
wash = 'Washing',
rinse = 'Rinsing',
spin = 'Spinning',
finish = 'Ended',
}
local code = tostring(code)
local translatedCode = translationcode[code]
if translatedCode == nil then
dz.log('codeToEnglish: Found unknown code: ' .. tostring(code),dz.LOG_ERROR )
end
return translatedCode or '?'
end
--Update text devices only when status is changed to prevent too many irrelevant log rows
local function updateTextOnlyWhenChanged(dz, textSensorName, newText)
if textSensorName ~= nil then
local textDevice = dz.devices(textSensorName)
if textDevice.text ~= newText then
textDevice.updateText(newText)
end
end
end
--Update percentage devices only when status is changed to prevent too many irrelevant log rows
local function updatePercentageOnlyWhenChanged(dz, percentageSensorName, newPercentage)
if percentageSensorName ~= nil then
local percentageDevice = dz.devices(percentageSensorName)
if percentageDevice.percentage ~= newPercentage then
-- percentage.updatePercentage(newPercentage)
percentageDevice.updatePercentage(newPercentage)
end
end
end
--Convert the time to Hour,Minute,second.
local function convertTime(dateString)
local pattern = '(%d+)%-(%d+)%-(%d+)%T(%d+):(%d+):(%d+)(%.*)' -- %d+ = 1 or more digits , %.* = 0 or more any character
local xyear, xmonth, xday, xhour, xminute, xseconds = dateString:match(pattern) -- split the string using the pattern
local convertedTimestamp = os.time({year = xyear, month = xmonth, day = xday, hour = xhour, min = xminute, sec = xseconds, isdst = os.date("*t", os.time()).isdst})
return os.date('%H:%M:%S', convertedTimestamp + 3600)
end
return
{
on =
{
timer =
{
'every minute', -- just an example to trigger the request
},
devices =
{
WM_TEST_SWITCH, -- Just on Switch to activated the script manually for testing.
},
httpResponses =
{
scriptVar, -- must match with the callback passed to the openURL command
},
},
logging =
{
level = domoticz.LOG_ERROR,
marker = scriptVar,
},
execute = function(dz, item)
local wm_status = dz.devices(WM_STATUS)
if item.isTimer or item.isDevice then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device .. '/states',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.ok then
if (item.isJSON) then
-- when recognized as json then dzVents will convert it to a table for you
rt = item.json.main
local endProgram = 'No active program'
local values = dz.utils.fromJSON(item.json.main.data.value)
local remainingTime = values.payload.remainingTime or values.payload["x.com.samsung.da.remainingTime"] or 'not found'
local progressPercentage = values.payload.progressPercentage or values.payload["x.com.samsung.da.progressPercentage"] or 'not found'
local completionTime = convertTime(rt.completionTime.value)
local switch = rt.switch.value
local washerWaterTemperature = rt.washerWaterTemperature.value
local washerJobState = rt.washerJobState.value
local washerCycle = rt.washerCycle.value
local washerSpinLevel = rt.washerSpinLevel.value
if switch == ('on') then
-- Turn on Domoticz switches updates only when Washer is Active.
dz.log('Debug if switch on:' .. switch, dz.LOG_DEBUG)
wm_status.switchOn().checkFirst() --turn on dz WM status switch
updateTextOnlyWhenChanged(dz, WM_TEMP, washerWaterTemperature )
updateTextOnlyWhenChanged(dz, WM_STATE, codeToEnglish(dz, washerJobState))
updateTextOnlyWhenChanged(dz, WM_SPIN, washerSpinLevel)
updateTextOnlyWhenChanged(dz, WM_REMAINING, remainingTime)
updateTextOnlyWhenChanged(dz, WM_COMPLETION, completionTime)
updateTextOnlyWhenChanged(dz, WM_PROGRAM, codeToEnglish(dz, washerCycle))
updatePercentageOnlyWhenChanged(dz, WM_PERCENT, progressPercentage)
else
--Update text devices with endProgram when switch is off
dz.log('Debug if switch off:' .. switch, dz.LOG_DEBUG)
wm_status.switchOff().checkFirst()
dz.log('washerMode if switch off:' .. endProgram, dz.LOG_DEBUG)
updateTextOnlyWhenChanged(dz, WM_TEMP, endProgram)
updateTextOnlyWhenChanged(dz, WM_STATE, endProgram)
updateTextOnlyWhenChanged(dz, WM_SPIN, endProgram)
updateTextOnlyWhenChanged(dz, WM_REMAINING, endProgram)
updateTextOnlyWhenChanged(dz, WM_COMPLETION, endProgram)
updateTextOnlyWhenChanged(dz, WM_PROGRAM, endProgram)
updatePercentageOnlyWhenChanged(dz, WM_PERCENT, 100)
end
return
else
dz.log('result was not recognized as a JSON', dz.LOG_ERROR)
end
else
dz.log('result was not OK', dz.LOG_ERROR)
end
dz.log(item, dz.LOG_ERROR) -- dump all to log as one long string
end
}
Then I have some equal code for the Dryer, I have still to do some work on the translations... :
Code: Select all
-- SETUP YOUR API CONFIGURATION HERE --
-- API key from https://account.smartthings.com/tokens (You'll need to register first and ensure your machine is on the same account)
-- Device ID from https://graph-eu01-euwest1.api.smartthings.com/device/list (click on your machine, then use the number in the URL after the last /)
local API = 'GET YOUR API KEY FROM THE URL ABOVE'
local Device = 'GET YOUR DEVICE ID FROM THE URL ABOVE'
-- CREATE YOUR OWN OUTPUTS HERE --
-- Create virtual sensors in Domoticz Hardware settings that will show the output from the washing machine.
-- Names are suggested [in square brackets], you need to input the device ID in (brackets) below.
local DR_TEST_SWITCH = (55) -- Virtual on switch to activated the script manually for testing.
local DR_PROGRAM = (56) -- Virtual device showing washing machine Program [Washing - Device type = text
local DR_COMPLETION = (57) -- Virtual device showing washing cycle completion time - Device type = text
local DR_REMAINING = (58) -- Virtual device showing time remaining on wash - Device type = text
local DR_STATUS = (61) -- Virtual device showing washing machine On/Off - Device type = on/off switch
local DR_PERCENT = (62) -- Virtual device showing washing machine percentage - Device type = percentage
-- ------------------------
local scriptVar = 'Dryer'
local LOGGING = true
--Convert Table_00_Course_* and WashingState to English
local function codeToEnglish(dz, code)
local translationcode =
{
Table_03_Course_16 = 'Cotton',
Table_03_Course_17 = 'Super Speed',
Table_03_Course_18 = 'Synthetics',
Table_03_Course_19 = 'Delicates',
Table_03_Course_1A = 'Wool',
Table_03_Course_1B = 'Bed Linnen',
Table_03_Course_1C = 'Shirts',
Table_03_Course_1D = 'Towels',
Table_03_Course_1E = 'Outdoor',
Table_03_Course_1F = 'Colored Wash',
Table_03_Course_20 = 'Iron Dry',
Table_03_Course_21 = 'Hygenic Care',
Table_03_Course_23 = '35\' Fast Dry',
Table_03_Course_24 = 'Cold Air',
Table_03_Course_25 = 'Warm Air',
Table_03_Course_26 = 'Air Wash',
Table_03_Course_27 = 'Time Program',
finish = 'Ended',
}
local code = tostring(code)
local translatedCode = translationcode[code:gsub('Table_03_Course_','')] or translationcode[code]
if translatedCode == nil then
dz.log('codeToEnglish: Found unknown code: ' .. tostring(code),dz.LOG_ERROR )
end
return translatedCode or '?'
end
--Update text devices only when status is changed to prevent too many irrelevant log rows
local function updateTextOnlyWhenChanged(dz, textSensorName, newText)
if textSensorName ~= nil then
local textDevice = dz.devices(textSensorName)
if textDevice.text ~= newText then
textDevice.updateText(newText)
end
end
end
--Update percentage devices only when status is changed to prevent too many irrelevant log rows
local function updatePercentageOnlyWhenChanged(dz, percentageSensorName, newPercentage)
if percentageSensorName ~= nil then
local percentageDevice = dz.devices(percentageSensorName)
if percentageDevice.percentage ~= newPercentage then
-- percentage.updatePercentage(newPercentage)
percentageDevice.updatePercentage(newPercentage)
end
end
end
--Convert the time to Hour,Minute,second.
local function convertTime(dateString)
local pattern = '(%d+)%-(%d+)%-(%d+)%T(%d+):(%d+):(%d+)(%.*)' -- %d+ = 1 or more digits , %.* = 0 or more any character
local xyear, xmonth, xday, xhour, xminute, xseconds = dateString:match(pattern) -- split the string using the pattern
local convertedTimestamp = os.time({year = xyear, month = xmonth, day = xday, hour = xhour, min = xminute, sec = xseconds, isdst = os.date("*t", os.time()).isdst})
return os.date('%H:%M:%S', convertedTimestamp + 3600)
end
return
{
on =
{
timer =
{
'every minute', -- just an example to trigger the request
},
devices =
{
DR_TEST_SWITCH, -- Just on Switch to activated the script manually for testing.
},
httpResponses =
{
scriptVar, -- must match with the callback passed to the openURL command
},
},
logging =
{
level = domoticz.LOG_ERROR,
marker = scriptVar,
},
execute = function(dz, item)
local dr_status = dz.devices(DR_STATUS)
local dr_percent = dz.devices(DR_PERCENT)
if item.isTimer or item.isDevice then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. Device .. '/states',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'GET',
callback = scriptVar, -- httpResponses above.
})
return
elseif item.ok then
if (item.isJSON) then
-- when recognized as json then dzVents will convert it to a table for you
rt = item.json.main
local endProgram = 'No active program'
local values = dz.utils.fromJSON(item.json.main.data.value)
local remainingTime = values.payload.remainingTime or values.payload["x.com.samsung.da.remainingTime"] or 'not found'
local progressPercentage = values.payload.progressPercentage or values.payload["x.com.samsung.da.progressPercentage"] or 'not found'
local completionTime = convertTime(rt.completionTime.value)
local switch = rt.switch.value
local dryerCycle = rt.dryerCycle.value
if switch == ('on') then
-- Turn on Domoticz switches updates only when Washer is Active.
dz.log('Debug if switch on:' .. switch, dz.LOG_DEBUG)
dr_status.switchOn().checkFirst() --turn on dz WM status switch
updateTextOnlyWhenChanged(dz, DR_REMAINING, remainingTime)
updateTextOnlyWhenChanged(dz, DR_COMPLETION, completionTime)
updateTextOnlyWhenChanged(dz, DR_PROGRAM, codeToEnglish(dz, dryerCycle))
updatePercentageOnlyWhenChanged(dz, DR_PERCENT, progressPercentage)
else
--Update text devices with endProgram when switch is off
dz.log('Debug if switch off:' .. switch, dz.LOG_DEBUG)
dr_status.switchOff().checkFirst()
dz.log('washerMode if switch off:' .. endProgram, dz.LOG_DEBUG)
updateTextOnlyWhenChanged(dz, DR_REMAINING, endProgram)
updateTextOnlyWhenChanged(dz, DR_COMPLETION, endProgram)
updateTextOnlyWhenChanged(dz, DR_PROGRAM, endProgram)
updatePercentageOnlyWhenChanged(dz, DR_PERCENT, 100)
end
return
else
dz.log('result was not recognized as a JSON', dz.LOG_ERROR)
end
else
dz.log('result was not OK', dz.LOG_ERROR)
end
dz.log(item, dz.LOG_ERROR) -- dump all to log as one long string
end
}
The combined version should contain all the above!
Code: Select all
-- SETUP YOUR API CONFIGURATION HERE --
-- API key from https://account.smartthings.com/tokens (You'll need to register first and ensure your machine is on the same account)
-- Device ID from https://graph-eu01-euwest1.api.smartthings.com/device/list (click on your machine, then use the number in the URL after the last /)
local API = 'GET YOUR API KEY FROM THE URL ABOVE'
local wmDevice = 'GET YOUR DEVICE ID FROM THE URL ABOVE'
local drDevice = 'GET YOUR DEVICE ID FROM THE URL ABOVE'
-- CREATE YOUR OWN OUTPUTS HERE --
-- Create virtual sensors in Domoticz Hardware settings that will show the output from the washing machine.
-- Names are suggested [in square brackets], you need to input the device ID in (brackets) below.
local TEST_SWITCH = (55) -- Virtual on switch to activated the script manually for testing.
local WM_PROGRAM = (47) -- Virtual device showing washing machine Program - Device type = text
local WM_COMPLETION = (48) -- Virtual device showing washing cycle completion time - Device type = text
local WM_SPIN = (49) -- Virtual device showing washing spin state - Device type = text
local WM_REMAINING = (50) -- Virtual device showing time remaining on wash - Device type = text
local WM_TEMP = (51) -- Virtual device showing washing machine Temperature - Device type = text
local WM_STATUS = (53) -- Virtual device showing washing machine On/Off - Device type = on/off switch
local WM_PERCENT = (54) -- Virtual device showing washing machine percentage - Device type = percentage
local WM_STATE = (52) -- Virtual device showing washing cycle state - Device type = text
local DR_PROGRAM = (56) -- Virtual device showing dryer Program - Device type = text
local DR_COMPLETION = (57) -- Virtual device showing drying cycle completion time - Device type = text
local DR_REMAINING = (58) -- Virtual device showing time remaining on wash - Device type = text
local DR_STATUS = (61) -- Virtual device showing dryer On/Off - Device type = on/off switch
local DR_PERCENT = (62) -- Virtual device showing dryer percentage - Device type = percentage
-- ------------------------
local wmScriptVar = 'WashingMachine'
local drScriptVar = 'Dryer'
local LOGGING = true
--Convert Table_00_Course_* and WashingState to English
local function codeToEnglish(dz, code)
local translationcode =
{
Table_00_Course_D0 = 'Cotton Wash',
Table_00_Course_D1 = 'Eco Cotton Wash',
Table_00_Course_D2 = 'Synthetics',
Table_00_Course_D3 = 'Delicates',
Table_00_Course_D4 = 'Rinse & Spin',
Table_00_Course_D5 = 'Drum Cleaning',
Table_00_Course_D6 = 'Bed Linnen',
Table_00_Course_D7 = 'Outdoor',
Table_00_Course_D8 = 'Wool',
Table_00_Course_D9 = 'Dark Wash',
Table_00_Course_DA = 'Super Eco Wash',
Table_00_Course_DB = 'Super Speed Wash',
Table_00_Course_DC = '15\' Quick Wash',
Table_00_Course_BA = 'Spin',
Table_02_Course_1B = 'Cotton',
Table_02_Course_1C = 'Eco 40-60',
Table_02_Course_1D = 'Super Speed Wash',
Table_02_Course_1E = '15\' Quick Wash',
Table_02_Course_1F = 'Intense Cold',
Table_02_Course_20 = 'Hygenic Steam',
Table_02_Course_21 = 'Colored Wash',
Table_02_Course_22 = 'Wool',
Table_02_Course_23 = 'Outdoor',
Table_02_Course_24 = 'Bed Linnen',
Table_02_Course_25 = 'Syntetic',
Table_02_Course_26 = 'Delicates',
Table_02_Course_27 = 'Rinse & Spin',
Table_02_Course_28 = 'Drain & Spin',
Table_02_Course_29 = 'Drum Cleaning',
Table_02_Course_2A = 'Jeans',
Table_02_Course_2B = 'All Wash',
Table_02_Course_2D = 'Silent Wash',
Table_02_Course_2E = 'Baby Clothes',
Table_02_Course_2F = 'Sportswear',
Table_02_Course_30 = 'Cloudy Day',
Table_02_Course_32 = 'Shirts',
Table_02_Course_33 = 'Towels',
Table_03_Course_16 = 'Cotton',
Table_03_Course_17 = 'Super Speed',
Table_03_Course_18 = 'Synthetics',
Table_03_Course_19 = 'Delicates',
Table_03_Course_1A = 'Wool',
Table_03_Course_1B = 'Bed Linnen',
Table_03_Course_1C = 'Shirts',
Table_03_Course_1D = 'Towels',
Table_03_Course_1E = 'Outdoor',
Table_03_Course_1F = 'Colored Wash',
Table_03_Course_20 = 'Iron Dry',
Table_03_Course_21 = 'Hygenic Care',
Table_03_Course_23 = '35\' Fast Dry',
Table_03_Course_24 = 'Cold Air',
Table_03_Course_25 = 'Warm Air',
Table_03_Course_26 = 'Air Wash',
Table_03_Course_27 = 'Time Program',
none = 'Nothing',
weightSensing = 'Weight Sensing',
wash = 'Washing',
rinse = 'Rinsing',
spin = 'Spinning',
finish = 'Ended',
}
local code = tostring(code)
local translatedCode = translationcode[code]
if translatedCode == nil then
dz.log('codeToEnglish: Found unknown code: ' .. tostring(code),dz.LOG_ERROR )
end
return translatedCode or '?'
end
--Update text devices only when status is changed to prevent too many irrelevant log rows
local function updateTextOnlyWhenChanged(dz, textSensorName, newText)
if textSensorName ~= nil then
local textDevice = dz.devices(textSensorName)
if textDevice.text ~= newText then
textDevice.updateText(newText)
end
end
end
--Update percentage devices only when status is changed to prevent too many irrelevant log rows
local function updatePercentageOnlyWhenChanged(dz, percentageSensorName, newPercentage)
if percentageSensorName ~= nil then
local percentageDevice = dz.devices(percentageSensorName)
if percentageDevice.percentage ~= newPercentage then
-- percentage.updatePercentage(newPercentage)
percentageDevice.updatePercentage(newPercentage)
end
end
end
--Update switch devices only when exists
local function updateSwitchOnlyWhenExists(dz, switchName, newState)
if switchName ~= nil then
local switch = dz.devices(switchName)
if newState == 'ON' then
switch.switchOn().checkFirst()
else
switch.switchOff().checkFirst()
end
end
end
--Convert the time to Hour,Minute,second.
local function convertTime(dateString)
local pattern = '(%d+)%-(%d+)%-(%d+)%T(%d+):(%d+):(%d+)(%.*)' -- %d+ = 1 or more digits , %.* = 0 or more any character
local xyear, xmonth, xday, xhour, xminute, xseconds = dateString:match(pattern) -- split the string using the pattern
local convertedTimestamp = os.time({year = xyear, month = xmonth, day = xday, hour = xhour, min = xminute, sec = xseconds, isdst = os.date("*t", os.time()).isdst})
return os.date('%H:%M:%S', convertedTimestamp + 3600)
end
return
{
on =
{
timer =
{
'every minute', -- just an example to trigger the request
},
devices =
{
TEST_SWITCH, -- Just on Switch to activated the script manually for testing.
},
httpResponses =
{
wmScriptVar, -- must match with the callback passed to the openURL command
drScriptVar, -- must match with the callback passed to the openURL command
},
},
logging =
{
level = domoticz.LOG_ERROR,
marker = 'SamsungWashingMachines',
},
execute = function(dz, item)
if item.isTimer or item.isDevice then
if wmDevice ~= nil and wmScriptVar ~= nill then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. wmDevice .. '/states',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'GET',
callback = wmScriptVar, -- httpResponses above.
})
end
if drDevice ~= nil and drScriptVar ~= nill then
dz.openURL({
url = 'https://api.smartthings.com/v1/devices/'.. drDevice .. '/states',
headers = { ['Authorization'] = 'Bearer '.. API },
method = 'GET',
callback = drScriptVar, -- httpResponses above.
})
end
return
elseif item.ok then
if (item.isJSON) then
-- when recognized as json then dzVents will convert it to a table for you
rt = item.json.main
local endProgram = 'No active program'
local values = dz.utils.fromJSON(item.json.main.data.value)
local remainingTime = values.payload.remainingTime or values.payload["x.com.samsung.da.remainingTime"] or 'not found'
local progressPercentage = values.payload.progressPercentage or values.payload["x.com.samsung.da.progressPercentage"] or 'not found'
local completionTime = convertTime(rt.completionTime.value)
local switch = rt.switch.value
-- Check whether it is a dryer or a washing machine
if rt.n.value == "[dryer] Samsung" then
local dryerCycle = rt.dryerCycle.value
if switch == ('on') then
-- Turn on Domoticz switches updates only when Washer is Active.
dz.log('Debug if switch on:' .. switch, dz.LOG_DEBUG)
updateSwitchOnlyWhenExists(dz, DR_STATUS, 'ON') --turn on dz DR status switch
updateTextOnlyWhenChanged(dz, DR_REMAINING, remainingTime)
updateTextOnlyWhenChanged(dz, DR_COMPLETION, completionTime)
updateTextOnlyWhenChanged(dz, DR_PROGRAM, codeToEnglish(dz, dryerCycle))
updatePercentageOnlyWhenChanged(dz, DR_PERCENT, progressPercentage)
else
--Update text devices with endProgram when switch is off
dz.log('Debug if switch off:' .. switch, dz.LOG_DEBUG)
updateSwitchOnlyWhenExists(dz, DR_STATUS, 'OFF') --turn off dz DR status switch
dz.log('dryerMode if switch off:' .. endProgram, dz.LOG_DEBUG)
updateTextOnlyWhenChanged(dz, DR_REMAINING, endProgram)
updateTextOnlyWhenChanged(dz, DR_COMPLETION, endProgram)
updateTextOnlyWhenChanged(dz, DR_PROGRAM, endProgram)
updatePercentageOnlyWhenChanged(dz, DR_PERCENT, 100)
end
else
local washerWaterTemperature = rt.washerWaterTemperature.value
local washerJobState = rt.washerJobState.value
local washerCycle = rt.washerCycle.value
local washerSpinLevel = rt.washerSpinLevel.value
if switch == ('on') then
-- Turn on Domoticz switches updates only when Washer is Active.
dz.log('Debug if switch on:' .. switch, dz.LOG_DEBUG)
updateSwitchOnlyWhenExists(dz, WM_STATUS, 'ON') --turn on dz WM status switch
updateTextOnlyWhenChanged(dz, WM_TEMP, washerWaterTemperature )
updateTextOnlyWhenChanged(dz, WM_STATE, codeToEnglish(dz, washerJobState))
updateTextOnlyWhenChanged(dz, WM_SPIN, washerSpinLevel)
updateTextOnlyWhenChanged(dz, WM_REMAINING, remainingTime)
updateTextOnlyWhenChanged(dz, WM_COMPLETION, completionTime)
updateTextOnlyWhenChanged(dz, WM_PROGRAM, codeToEnglish(dz, washerCycle))
updatePercentageOnlyWhenChanged(dz, WM_PERCENT, progressPercentage)
else
--Update text devices with endProgram when switch is off
dz.log('Debug if switch off:' .. switch, dz.LOG_DEBUG)
updateSwitchOnlyWhenExists(dz, WM_STATUS, 'OFF') --turn off dz WM status switch
dz.log('washerMode if switch off:' .. endProgram, dz.LOG_DEBUG)
updateTextOnlyWhenChanged(dz, WM_TEMP, endProgram)
updateTextOnlyWhenChanged(dz, WM_STATE, endProgram)
updateTextOnlyWhenChanged(dz, WM_SPIN, endProgram)
updateTextOnlyWhenChanged(dz, WM_REMAINING, endProgram)
updateTextOnlyWhenChanged(dz, WM_COMPLETION, endProgram)
updateTextOnlyWhenChanged(dz, WM_PROGRAM, endProgram)
updatePercentageOnlyWhenChanged(dz, WM_PERCENT, 100)
end
end
return
else
dz.log('result was not recognized as a JSON', dz.LOG_ERROR)
end
else
dz.log('result was not OK', dz.LOG_ERROR)
end
dz.log(item, dz.LOG_ERROR) -- dump all to log as one long string
end
}
Ofcourse I have some wild plans:
1.
First of all finish the translations on the dryer. Done
2.
Then I want to combine the two into one dzVents script Done as well
3. Rewrite the scripts into an python plugin to have one single washing machine "widget" with all needed info
Never done so, but a nice hobby project.