Samsung Washmachine read status from json "SOLVED"  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Wednesday 31 March 2021 10:42
Robinjoo94 wrote: Wednesday 31 March 2021 10:31 Same error messages
That should not be possible as the dz.log(item.json.main.data.value) does not call the function that contains line 425 of /home/pi/domoticz/dzVents/runtime/Utils.lua

Can you share the script as it is now and the complete log?
Appologies, I did something wrong somewhere I think.

Code: Select all

dz.log(item.json.main.data.value, dz.LOG_ERROR)
dz.utils.dumpTable(dz.utils.fromJSON(item.json.main.data.value))
Outputs the following (Washing mashine in sleep):

Code: Select all

2021-03-31 12:07:32.008 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: {"payload":{"rt":["x.com.samsung.da.wm.setinfo"],"if":["oic.if.baseline","oic.if.a"],"x.com.samsung.da.isModelSettingWithoutSC":"true","x.com.samsung.da.aiCourse":"true_formobile"}}
2021-03-31 12:07:32.508 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: {"payload":{"rt":["x.com.samsung.da.rm.wifi"],"if":["oic.if.baseline","oic.if.s"],"x.com.samsung.rm.rssi":[-60]}}
I have not found a way to change the dumpTable to dz.LOG_ERROR, since my Domoticz is configured to log Errors only, a bit of a beginner there ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Wednesday 31 March 2021 12:11 I have not found a way to change the dumpTable to dz.LOG_ERROR, since my Domoticz is configured to log Errors only, a bit of a beginner there ;)
The utils.dumpTable should ignore the settings for dzVents logging and always show up in the log.
This is what I see when feeding your item.json.main.data.value to it.

Code: Select all

2021-03-31 12:21:00.542  Status: dzVents: > payload:
2021-03-31 12:21:00.542  Status: dzVents: >     x.com.samsung.da.aiCourse: true_formobile
2021-03-31 12:21:00.542  Status: dzVents: >     x.com.samsung.da.isModelSettingWithoutSC: true
2021-03-31 12:21:00.542  Status: dzVents: >     if:
2021-03-31 12:21:00.542  Status: dzVents: >             1: oic.if.baseline
2021-03-31 12:21:00.542  Status: dzVents: >             2: oic.if.a
2021-03-31 12:21:00.542  Status: dzVents: >     rt:
2021-03-31 12:21:00.542  Status: dzVents: >             1: x.com.samsung.da.wm.setinfo

Now the interesting part is why this is not already a Lua subtable of item.json
To find out; can you replace the lines

Code: Select all

dz.log(item.json.main.data.value, dz.LOG_ERROR)
dz.utils.dumpTable(dz.utils.fromJSON(item.json.main.data.value))
with

Code: Select all

dz.log(item.json,  dz.LOG_ERROR)

dz.log('Type of value: ' ..  type(item.json.main.data.value),  dz.LOG_ERROR)
dz.log('Type of json:  ' ..  type(item.json),  dz.LOG_ERROR)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Wednesday 31 March 2021 12:32 Now the interesting part is why this is not already a Lua subtable of item.json
To find out; can you replace the lines

Code: Select all

dz.log(item.json.main.data.value, dz.LOG_ERROR)
dz.utils.dumpTable(dz.utils.fromJSON(item.json.main.data.value))
with

Code: Select all

dz.log(item.json,  dz.LOG_ERROR)

dz.log('Type of value: ' ..  type(item.json.main.data.value),  dz.LOG_ERROR)
dz.log('Type of json:  ' ..  type(item.json),  dz.LOG_ERROR)
Ok I have set enable status logging of domoticz, this does not help....
The debugging you asked for:

Code: Select all

2021-03-31 16:23:16.619 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: Type of value: string
2021-03-31 16:23:16.619 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: Type of json: table
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Wednesday 31 March 2021 16:32 Ok I have set enable status logging of domoticz, this does not help....
Sorry but I need the result of the utils.dumpTable() statement to be able to help. No idea why your system does not show the expected lines.
You could try to log to an os file.


The domoticz logfile location and other settings are defined in /etc/init.d/domoticz.sh
the relevant settings are in set to the DAEMON_ARGS var.

with an editor of choice

Code: Select all

DAEMON_ARGS="$DAEMON_ARGS -log /var/log/domoticz.log" # or any other OS file
#DAEMON_ARGS="$DAEMON_ARGS -loglevel  normal,status,error, debug" # debug disabled for now
DAEMON_ARGS="$DAEMON_ARGS -loglevel  normal,status,error" # these loglevels will make it to the logfile
#DAEMON_ARGS="$DAEMON_ARGS -debuglevel normal,hardware,received,webserver,eventsystem,python,thread_id"

Code: Select all

sudo systemctl daemon-reload
sudo service domoticz stop
sudo service domoticz start
sudo tail -f  /var/log/domoticz.log
The system and other logfiles can be found with sudo ls -lrt /var/log/*log
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Wednesday 31 March 2021 17:13
Robinjoo94 wrote: Wednesday 31 March 2021 16:32 Ok I have set enable status logging of domoticz, this does not help....
Sorry but I need the result of the utils.dumpTable() statement to be able to help. No idea why your system does not show the expected lines.
You could try to log to an os file.


The domoticz logfile location and other settings are defined in /etc/init.d/domoticz.sh
the relevant settings are in set to the DAEMON_ARGS var.

with an editor of choice

Code: Select all

DAEMON_ARGS="$DAEMON_ARGS -log /var/log/domoticz.log" # or any other OS file
#DAEMON_ARGS="$DAEMON_ARGS -loglevel  normal,status,error, debug" # debug disabled for now
DAEMON_ARGS="$DAEMON_ARGS -loglevel  normal,status,error" # these loglevels will make it to the logfile
#DAEMON_ARGS="$DAEMON_ARGS -debuglevel normal,hardware,received,webserver,eventsystem,python,thread_id"

Code: Select all

sudo systemctl daemon-reload
sudo service domoticz stop
sudo service domoticz start
sudo tail -f  /var/log/domoticz.log
The system and other logfiles can be found with sudo ls -lrt /var/log/*log
Thank you very much for your fast responses and your patience, I misinterpreted the log, therfore did not post the table here.
I still would very much appreciate to have (optional) control over the loglevel of dumpTable, but that is a different topic ;) This since I have set loglevel to error only in /etc/init.d/domoticz.sh.

Dryer log:

Code: Select all

2021-03-31 18:02:01.156 Status: dzVents: > payload:
2021-03-31 18:02:01.156 Status: dzVents: > x.com.samsung.rm.rssi:
2021-03-31 18:02:01.156 Status: dzVents: > 1: -60
2021-03-31 18:02:01.156 Status: dzVents: > rt:
2021-03-31 18:02:01.156 Status: dzVents: > 1: x.com.samsung.da.rm.wifi
2021-03-31 18:02:01.156 Status: dzVents: > if:
2021-03-31 18:02:01.156 Status: dzVents: > 1: oic.if.baseline
2021-03-31 18:02:01.156 Status: dzVents: > 2: oic.if.s
Washing machine log:

Code: Select all

2021-03-31 18:02:00.901 Status: dzVents: > payload:
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.delayEndTime: 00:00:00
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.supportedProgress:
2021-03-31 18:02:00.901 Status: dzVents: > 1: None
2021-03-31 18:02:00.901 Status: dzVents: > 2: Weightsensing
2021-03-31 18:02:00.901 Status: dzVents: > 3: Wash
2021-03-31 18:02:00.901 Status: dzVents: > 4: Rinse
2021-03-31 18:02:00.901 Status: dzVents: > 5: Spin
2021-03-31 18:02:00.901 Status: dzVents: > 6: Finish
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.state: Ready
2021-03-31 18:02:00.901 Status: dzVents: > if:
2021-03-31 18:02:00.901 Status: dzVents: > 1: oic.if.baseline
2021-03-31 18:02:00.901 Status: dzVents: > 2: oic.if.a
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.progress: None
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.progressPercentage: 1
2021-03-31 18:02:00.901 Status: dzVents: > rt:
2021-03-31 18:02:00.901 Status: dzVents: > 1: x.com.samsung.da.operation
2021-03-31 18:02:00.901 Status: dzVents: > x.com.samsung.da.remainingTime: 02:06:00
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Wednesday 31 March 2021 18:07 I still would very much appreciate to have (optional) control over the loglevel of dumpTable, but that is a different topic ;) This since I have set loglevel to error only in /etc/init.d/domoticz.sh.
Sorry but that's not going to be implemented. If you want to you can always modify domoticz/dzVents/runtime/Utils.lua yourself locally.

Can you also share the result of dz.utils.dumpTable(item.json)?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Wednesday 31 March 2021 20:02
Robinjoo94 wrote: Wednesday 31 March 2021 18:07 I still would very much appreciate to have (optional) control over the loglevel of dumpTable, but that is a different topic ;) This since I have set loglevel to error only in /etc/init.d/domoticz.sh.
Sorry but that's not going to be implemented. If you want to you can always modify domoticz/dzVents/runtime/Utils.lua yourself locally.

Can you also share the result of dz.utils.dumpTable(item.json)?
Ok, fine for me, I will do the adjustments locally :)

That output is a lot bigger, but here we go washer:

Code: Select all

2021-03-31 21:30:01.291 Status: dzVents: > supportedDensity:
2021-03-31 21:30:01.291 Status: dzVents: > value: ["normal","high","extraHigh"]
2021-03-31 21:30:01.291 Status: dzVents: > waterConsumption:
2021-03-31 21:30:01.291 Status: dzVents: > st:
2021-03-31 21:30:01.291 Status: dzVents: > supportedWasherRinseCycles:
2021-03-31 21:30:01.291 Status: dzVents: > value: ["0","1","2","3","4","5"]
2021-03-31 21:30:01.291 Status: dzVents: > maxNumberOfPresets:
2021-03-31 21:30:01.291 Status: dzVents: > value: 10
2021-03-31 21:30:01.291 Status: dzVents: > n:
2021-03-31 21:30:01.291 Status: dzVents: > value: [washer] Samsung
2021-03-31 21:30:01.291 Status: dzVents: > supportedWaterLevel:
2021-03-31 21:30:01.291 Status: dzVents: > referenceTable:
2021-03-31 21:30:01.291 Status: dzVents: > value: {"id":"Table_02"}
2021-03-31 21:30:01.291 Status: dzVents: > detergentType:
2021-03-31 21:30:01.291 Status: dzVents: > value: none
2021-03-31 21:30:01.291 Status: dzVents: > modelClassificationCode:
2021-03-31 21:30:01.291 Status: dzVents: > value: 20010002001411E702A3020700000000
2021-03-31 21:30:01.291 Status: dzVents: > washingTime:
2021-03-31 21:30:01.291 Status: dzVents: > unit: min
2021-03-31 21:30:01.291 Status: dzVents: > washerSpinLevel:
2021-03-31 21:30:01.291 Status: dzVents: > value: 1600
2021-03-31 21:30:01.291 Status: dzVents: > mnpv:
2021-03-31 21:30:01.291 Status: dzVents: > value: DAWIT 2.0
2021-03-31 21:30:01.291 Status: dzVents: > supportedWasherWaterTemperature:
2021-03-31 21:30:01.291 Status: dzVents: > value: ["none","cold","20","30","40","60","90"]
2021-03-31 21:30:01.291 Status: dzVents: > mnmn:
2021-03-31 21:30:01.291 Status: dzVents: > value: Samsung Electronics
2021-03-31 21:30:01.291 Status: dzVents: > serialNumber:
2021-03-31 21:30:01.291 Status: dzVents: > versionNumber:
2021-03-31 21:30:01.291 Status: dzVents: > value: 21032601
2021-03-31 21:30:01.291 Status: dzVents: > mnmo:
2021-03-31 21:30:01.291 Status: dzVents: > value: DA_WM_TP2_20_COMMON|20260041|20010002001411E702A3020700000000
2021-03-31 21:30:01.292 Status: dzVents: > waterValve:
2021-03-31 21:30:01.292 Status: dzVents: > disabledCapabilities:
2021-03-31 21:30:01.292 Status: dzVents: > value: ["samsungce.washerCyclePreset","samsungce.waterConsumptionReport","custom.washerSoilLevel","custom.dryerWrinklePrevent","samsungce.washerWaterLevel","samsungce.washerWaterValve","samsungce.washerWashingTime","custom.washerAutoDetergent","custom.washerAutoSoftener","samsungce.welcomeMessage"]
2021-03-31 21:30:01.292 Status: dzVents: > mnsl:
2021-03-31 21:30:01.292 Status: dzVents: > remainingAmount:
2021-03-31 21:30:01.292 Status: dzVents: > value: 0
2021-03-31 21:30:01.292 Status: dzVents: > unit: cc
2021-03-31 21:30:01.292 Status: dzVents: > jobBeginningStatus:
2021-03-31 21:30:01.292 Status: dzVents: > value: None
2021-03-31 21:30:01.292 Status: dzVents: > mnos:
2021-03-31 21:30:01.292 Status: dzVents: > value: TizenRT 1.0 + IPv6
2021-03-31 21:30:01.292 Status: dzVents: > vid:
2021-03-31 21:30:01.292 Status: dzVents: > value: DA-WM-WM-000001
2021-03-31 21:30:01.292 Status: dzVents: > mndt:
2021-03-31 21:30:01.292 Status: dzVents: > supportedCycles:
2021-03-31 21:30:01.292 Status: dzVents: > value: [{"cycle":"1C","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A7FF","default":"1600","options":["rinseHold","noSpin","400","800","1000","1200","1400","1600"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"8410","default":"40","options":["40"]}}},{"cycle":"2B","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A67F","default":"1400","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"9308","default":"3","options":["3"]},"waterTemperature":{"raw":"8410","default":"40","options":["40"]}}},{"cycle":"1B","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A7FF","default":"1600","options":["rinseHold","noSpin","400","800","1000","1200","1400","1600"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"847E","default":"40","options":["cold","20","30","40","60","90"]}}},{"cycle":"1E","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A33F","default":"800","options":["rinseHold","noSpin","400","800","1000","1200"]},"rinseCycle":{"raw":"933F","default":"3","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"811E","default":"cold","options":["cold","20","30","40"]}}},{"cycle":"1D","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A67F","default":"1400","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"841E","default":"40","options":["cold","20","30","40"]}}},{"cycle":"1F","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A57F","default":"1200","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"8102","default":"cold","options":["cold"]}}},{"cycle":"25","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A57F","default":"1200","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"843E","default":"40","options":["cold","20","30","40","60"]}}},{"cycle":"26","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A30F","default":"800","options":["rinseHold","noSpin","400","800"]},"rinseCycle":{"raw":"920F","default":"2","options":["0","1","2","3"]},"waterTemperature":{"raw":"831E","default":"30","options":["cold","20","30","40"]}}},{"cycle":"33","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A67F","default":"1400","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"933F","default":"3","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"857E","default":"60","options":["cold","20","30","40","60","90"]}}},{"cycle":"24","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A30F","default":"800","options":["rinseHold","noSpin","400","800"]},"rinseCycle":{"raw":"930F","default":"3","options":["0","1","2","3"]},"waterTemperature":{"raw":"841E","default":"40","options":["cold","20","30","40"]}}},{"cycle":"32","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A37F","default":"800","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"923F","default":"2","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"833E","default":"30","options":["cold","20","30","40","60"]}}},{"cycle":"20","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A67F","default":"1400","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"943F","default":"4","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"857E","default":"60","options":["cold","20","30","40","60","90"]}}},{"cycle":"22","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A30F","default":"800","options":["rinseHold","noSpin","400","800"]},"rinseCycle":{"raw":"920F","default":"2","options":["0","1","2","3"]},"waterTemperature":{"raw":"841E","default":"40","options":["cold","20","30","40"]}}},{"cycle":"23","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A57F","default":"1200","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"930F","default":"3","options":["0","1","2","3"]},"waterTemperature":{"raw":"831E","default":"30","options":["cold","20","30","40"]}}},{"cycle":"2F","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A30F","default":"800","options":["rinseHold","noSpin","400","800"]},"rinseCycle":{"raw":"933F","default":"3","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"831E","default":"30","options":["cold","20","30","40"]}}},{"cycle":"21","supportedOptions":{"bubbleSoak":{"raw":"3500","options":[]},"spinLevel":{"raw":"A57F","default":"1200","options":["rinseHold","noSpin","400","800","1000","1200","1400"]},"rinseCycle":{"raw":"933F","default":"3","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"841E","default":"40","options":["cold","20","30","40"]}}},{"cycle":"2A","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A30F","default":"800","options":["rinseHold","noSpin","400","800"]},"rinseCycle":{"raw":"933F","default":"3","options":["0","1","2","3","4","5"]},"waterTemperature":{"raw":"831E","default":"30","options":["cold","20","30","40"]}}},{"cycle":"2E","supportedOptions":{"bubbleSoak":{"raw":"35F0","default":"off","options":["on","off"]},"spinLevel":{"raw":"A67F","defaul
2021-03-31 21:30:01.292 Status: dzVents: > mnml:
2021-03-31 21:30:01.292 Status: dzVents: > value: http://www.samsung.com
2021-03-31 21:30:01.292 Status: dzVents: > amount:
2021-03-31 21:30:01.292 Status: dzVents: > value: standard
2021-03-31 21:30:01.292 Status: dzVents: > orderThreshold:
2021-03-31 21:30:01.292 Status: dzVents: > value: 0
2021-03-31 21:30:01.292 Status: dzVents: > unit: cc
2021-03-31 21:30:01.292 Status: dzVents: > presets:
2021-03-31 21:30:01.292 Status: dzVents: > machineState:
2021-03-31 21:30:01.292 Status: dzVents: > value: stop
2021-03-31 21:30:01.292 Status: dzVents: > supportedAmount:
2021-03-31 21:30:01.292 Status: dzVents: > value: ["none","less","standard","extra"]
2021-03-31 21:30:01.293 Status: dzVents: > washerAutoDetergent:
2021-03-31 21:30:01.293 Status: dzVents: > dryerDryLevel:
2021-03-31 21:30:01.293 Status: dzVents: > washerWaterTemperature:
2021-03-31 21:30:01.293 Status: dzVents: > value: 40
2021-03-31 21:30:01.293 Status: dzVents: > pi:
2021-03-31 21:30:01.293 Status: dzVents: > value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2021-03-31 21:30:01.293 Status: dzVents: > washerSoilLevel:
2021-03-31 21:30:01.293 Status: dzVents: > washerAutoSoftener:
2021-03-31 21:30:01.293 Status: dzVents: > dmv:
2021-03-31 21:30:01.293 Status: dzVents: > value: res.1.1.0,sh.1.1.0
2021-03-31 21:30:01.293 Status: dzVents: > modelName:
2021-03-31 21:30:01.293 Status: dzVents: > supportedCourses:
2021-03-31 21:30:01.293 Status: dzVents: > value: ["1C","2B","1B","1E","1D","1F","25","26","33","24","32","20","22","23","2F","21","2A","2E","2D","30","27","28","29"]
2021-03-31 21:30:01.293 Status: dzVents: > alarmEnabled:
2021-03-31 21:30:01.293 Status: dzVents: > value: false
2021-03-31 21:30:01.293 Status: dzVents: > binaryId:
2021-03-31 21:30:01.293 Status: dzVents: > value: DA_WM_TP2_20_COMMON
2021-03-31 21:30:01.293 Status: dzVents: > supportedWaterValve:
2021-03-31 21:30:01.293 Status: dzVents: > mnfv:
2021-03-31 21:30:01.293 Status: dzVents: > value: DA_WM_TP2_20_COMMON_30210226
2021-03-31 21:30:01.293 Status: dzVents: > icv:
2021-03-31 21:30:01.293 Status: dzVents: > value: core.1.1.0
2021-03-31 21:30:01.293 Status: dzVents: > supportedDryerDryLevel:
2021-03-31 21:30:01.293 Status: dzVents: > welcomeMessage:
2021-03-31 21:30:01.293 Status: dzVents: > softenerType:
2021-03-31 21:30:01.293 Status: dzVents: > value: unknown
2021-03-31 21:30:01.293 Status: dzVents: > washerRinseCycles:
2021-03-31 21:30:01.293 Status: dzVents: > value: 2
2021-03-31 21:30:01.293 Status: dzVents: > dosage:
2021-03-31 21:30:01.293 Status: dzVents: > value: 0
2021-03-31 21:30:01.293 Status: dzVents: > unit: cc
2021-03-31 21:30:01.293 Status: dzVents: > switch:
2021-03-31 21:30:01.293 Status: dzVents: > value: off
2021-03-31 21:30:01.293 Status: dzVents: > micomAssayCode:
2021-03-31 21:30:01.293 Status: dzVents: > value: 20260041
2021-03-31 21:30:01.294 Status: dzVents: > powerConsumption:
2021-03-31 21:30:01.294 Status: dzVents: > value: {"energy":8500,"deltaEnergy":0,"power":0,"powerEnergy":0.0,"persistedEnergy":0,"energySaved":0,"start":"2021-03-31T10:16:05Z","end":"2021-03-31T10:16:05Z"}
2021-03-31 21:30:01.294 Status: dzVents: > di:
2021-03-31 21:30:01.294 Status: dzVents: > value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2021-03-31 21:30:01.294 Status: dzVents: > supportedWasherSoilLevel:
Dryer:

Code: Select all

2021-03-31 21:31:50.133 Status: dzVents: Info: Handling httpResponse-events for: "Dryer"
2021-03-31 21:31:50.146 Status: dzVents: > main:
2021-03-31 21:31:50.146 Status: dzVents: > initialAmount:
2021-03-31 21:31:50.146 Status: dzVents: > value: 0
2021-03-31 21:31:50.146 Status: dzVents: > unit: cc
2021-03-31 21:31:50.146 Status: dzVents: > orderThreshold:
2021-03-31 21:31:50.146 Status: dzVents: > value: 0
2021-03-31 21:31:50.146 Status: dzVents: > unit: cc
2021-03-31 21:31:50.146 Status: dzVents: > supportedCourses:
2021-03-31 21:31:50.146 Status: dzVents: > value: ["16","23","17","1F","18","19","1D","1B","1C","21","1A","1E","20","27","25","24","26"]
2021-03-31 21:31:50.146 Status: dzVents: > modelName:
2021-03-31 21:31:50.146 Status: dzVents: > powerConsumption:
2021-03-31 21:31:50.146 Status: dzVents: > value: {"energy":5300,"deltaEnergy":0,"power":0,"powerEnergy":0.0,"persistedEnergy":0,"energySaved":0,"start":"2021-03-31T07:53:31Z","end":"2021-03-31T07:57:28Z"}
2021-03-31 21:31:50.146 Status: dzVents: > st:
2021-03-31 21:31:50.146 Status: dzVents: > mnos:
2021-03-31 21:31:50.146 Status: dzVents: > value: TizenRT 1.0 + IPv6
2021-03-31 21:31:50.146 Status: dzVents: > dryerDryLevel:
2021-03-31 21:31:50.146 Status: dzVents: > value: 2
2021-03-31 21:31:50.146 Status: dzVents: > di:
2021-03-31 21:31:50.146 Status: dzVents: > value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2021-03-31 21:31:50.146 Status: dzVents: > remainingAmount:
2021-03-31 21:31:50.146 Status: dzVents: > value: 0
2021-03-31 21:31:50.146 Status: dzVents: > unit: cc
2021-03-31 21:31:50.146 Status: dzVents: > machineState:
2021-03-31 21:31:50.146 Status: dzVents: > value: stop
2021-03-31 21:31:50.146 Status: dzVents: > switch:
2021-03-31 21:31:50.146 Status: dzVents: > value: off
2021-03-31 21:31:50.146 Status: dzVents: > micomAssayCode:
2021-03-31 21:31:50.146 Status: dzVents: > dryingTime:
2021-03-31 21:31:50.146 Status: dzVents: > unit: min
2021-03-31 21:31:50.146 Status: dzVents: > binaryId:
2021-03-31 21:31:50.146 Status: dzVents: > detergentType:
2021-03-31 21:31:50.146 Status: dzVents: > mnhw:
2021-03-31 21:31:50.146 Status: dzVents: > value: MediaTek
2021-03-31 21:31:50.146 Status: dzVents: > pi:
2021-03-31 21:31:50.146 Status: dzVents: > value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2021-03-31 21:31:50.146 Status: dzVents: > supportedMachineStates:
2021-03-31 21:31:50.146 Status: dzVents: > supportedDryingTime:
2021-03-31 21:31:50.147 Status: dzVents: > completionTime:
2021-03-31 21:31:50.147 Status: dzVents: > value: 2021-03-31T11:43:30Z
2021-03-31 21:31:50.147 Status: dzVents: > presets:
2021-03-31 21:31:50.147 Status: dzVents: > lockState:
2021-03-31 21:31:50.147 Status: dzVents: > value: unlocked
2021-03-31 21:31:50.147 Status: dzVents: > jobBeginningStatus:
2021-03-31 21:31:50.147 Status: dzVents: > value: None
2021-03-31 21:31:50.147 Status: dzVents: > dosage:
2021-03-31 21:31:50.147 Status: dzVents: > value: 0
2021-03-31 21:31:50.147 Status: dzVents: > unit: cc
2021-03-31 21:31:50.147 Status: dzVents: > maxNumberOfPresets:
2021-03-31 21:31:50.147 Status: dzVents: > supportedDryingTemperature:
2021-03-31 21:31:50.147 Status: dzVents: > welcomeMessage:
2021-03-31 21:31:50.147 Status: dzVents: > versionNumber:
2021-03-31 21:31:50.147 Status: dzVents: > value: 21030301
2021-03-31 21:31:50.147 Status: dzVents: > supportedCycles:
2021-03-31 21:31:50.147 Status: dzVents: > value: [{"cycle":"16","supportedOptions":{"dryingLevel":{"raw":"D20E","options":[]}}},{"cycle":"23","supportedOptions":{"dryingLevel":{"raw":"D000","options":[]}}},{"cycle":"17","supportedOptions":{"dryingLevel":{"raw":"D204","options":[]}}},{"cycle":"1F","supportedOptions":{"dryingLevel":{"raw":"D20E","options":[]}}},{"cycle":"18","supportedOptions":{"dryingLevel":{"raw":"D20E","options":[]}}},{"cycle":"19","supportedOptions":{"dryingLevel":{"raw":"D204","options":[]}}},{"cycle":"1D","supportedOptions":{"dryingLevel":{"raw":"D204","options":[]}}},{"cycle":"1B","supportedOptions":{"dryingLevel":{"raw":"D204","options":[]}}},{"cycle":"1C","supportedOptions":{"dryingLevel":{"raw":"D20E","options":[]}}},{"cycle":"21","supportedOptions":{"dryingLevel":{"raw":"D308","options":[]}}},{"cycle":"1A","supportedOptions":{"dryingLevel":{"raw":"D102","options":[]}}},{"cycle":"1E","supportedOptions":{"dryingLevel":{"raw":"D204","options":[]}}},{"cycle":"20","supportedOptions":{"dryingLevel":{"raw":"D102","options":[]}}},{"cycle":"27","supportedOptions":{"dryingLevel":{"raw":"D000","options":[]}}},{"cycle":"25","supportedOptions":{"dryingLevel":{"raw":"D000","options":[]}}},{"cycle":"24","supportedOptions":{"dryingLevel":{"raw":"D000","options":[]}}},{"cycle":"26","supportedOptions":{"dryingLevel":{"raw":"D10E","options":[]}}}]
2021-03-31 21:31:50.147 Status: dzVents: > n:
2021-03-31 21:31:50.147 Status: dzVents: > value: [dryer] Samsung
2021-03-31 21:31:50.147 Status: dzVents: > icv:
2021-03-31 21:31:50.147 Status: dzVents: > value: core.1.1.0
2021-03-31 21:31:50.147 Status: dzVents: > dryerAutoCycleLink:
2021-03-31 21:31:50.147 Status: dzVents: > value: off
2021-03-31 21:31:50.147 Status: dzVents: > description:
2021-03-31 21:31:50.147 Status: dzVents: > supportedDryerDryLevel:
2021-03-31 21:31:50.147 Status: dzVents: > value: ["none","1","2","3"]
2021-03-31 21:31:50.147 Status: dzVents: > alarmEnabled:
2021-03-31 21:31:50.147 Status: dzVents: > value: false
2021-03-31 21:31:50.147 Status: dzVents: > modelClassificationCode:
2021-03-31 21:31:50.147 Status: dzVents: > dryingTemperature:
2021-03-31 21:31:50.147 Status: dzVents: > referenceTable:
2021-03-31 21:31:50.147 Status: dzVents: > value: {"id":"Table_03"}
2021-03-31 21:31:50.147 Status: dzVents: > dryerCycle:
2021-03-31 21:31:50.147 Status: dzVents: > value: Table_03_Course_16
2021-03-31 21:31:50.148 Status: dzVents: > mnpv:
2021-03-31 21:31:50.148 Status: dzVents: > value: DAWIT 2.0
2021-03-31 21:31:50.148 Status: dzVents: > mnfv:
2021-03-31 21:31:50.148 Status: dzVents: > value: DA_WM_TP2_20_COMMON_30210226
2021-03-31 21:31:50.148 Status: dzVents: > serialNumberExtra:
2021-03-31 21:31:50.148 Status: dzVents: > serialNumber:
2021-03-31 21:31:50.148 Status: dzVents: > disabledCapabilities:
2021-03-31 21:31:50.148 Status: dzVents: > value: ["samsungce.dryerDryingTemperature","samsungce.welcomeMessage"]
2021-03-31 21:31:50.148 Status: dzVents: > dryerWrinklePrevent:
2021-03-31 21:31:50.148 Status: dzVents: > value: off
2021-03-31 21:31:50.148 Status: dzVents: > data:
2021-03-31 21:31:50.148 Status: dzVents: > value: {"payload":{"rt":["x.com.samsung.da.rm.wifi"],"if":["oic.if.baseline","oic.if.s"],"x.com.samsung.rm.rssi":[-60]}}
2021-03-31 21:31:50.148 Status: dzVents: > mnsl:
2021-03-31 21:31:50.148 Status: dzVents: > mndt:
2021-03-31 21:31:50.148 Status: dzVents: > vid:
2021-03-31 21:31:50.148 Status: dzVents: > value: DA-WM-WD-000001
2021-03-31 21:31:50.148 Status: dzVents: > mnmn:
2021-03-31 21:31:50.148 Status: dzVents: > value: Samsung Electronics
2021-03-31 21:31:50.148 Status: dzVents: > remoteControlEnabled:
2021-03-31 21:31:50.148 Status: dzVents: > value: false
2021-03-31 21:31:50.148 Status: dzVents: > dmv:
2021-03-31 21:31:50.148 Status: dzVents: > value: 1.2.1
2021-03-31 21:31:50.148 Status: dzVents: > dryerJobState:
2021-03-31 21:31:50.148 Status: dzVents: > value: none
2021-03-31 21:31:50.148 Status: dzVents: > mnmo:
2021-03-31 21:31:50.148 Status: dzVents: > value: DA_WM_TP2_20_COMMON|20262941|300101020014110002A3030700000000
2021-03-31 21:31:50.148 Status: dzVents: > mnml:
2021-03-31 21:31:50.148 Status: dzVents: > value: http://www.samsung.com
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Wednesday 31 March 2021 21:32
Thx. I now remember that there was something strange with this JSON. It is a serialized JSON inside a normal JSON so for every serialized JSON a subsequent dz.utils.fromJSON needs to be called.
I could try to modify the dz.utils.fromJSON to do this in one pass but because I have no access to the original data I would need an example.

Code: Select all

dz.log(item.data, dz.LOG_FORCE )
would output such an example to the logfile.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Thursday 01 April 2021 1:07
Robinjoo94 wrote: Wednesday 31 March 2021 21:32
Thx. I now remember that there was something strange with this JSON. It is a serialized JSON inside a normal JSON so for every serialized JSON a subsequent dz.utils.fromJSON needs to be called.
I could try to modify the dz.utils.fromJSON to do this in one pass but because I have no access to the original data I would need an example.

Code: Select all

dz.log(item.data, dz.LOG_FORCE )
would output such an example to the logfile.
Washing machine:

Code: Select all

2021-04-01 16:29:19.700 Status: dzVents: !Info: SamsungWashingMachines: {"main":{"supportedWashingTimes":{"value":null},"washerAutoSoftener":{"value":null},"washingTime":{"value":null,"unit":"min"},"mnfv":{"value":"DA_WM_TP2_20_COMMON_30210226"},"data":{"value":"{\"payload\":{\"rt\":[\"x.com.samsung.da.washer\"],\"if\":[\"oic.if.baseline\",\"oic.if.a\"]}}"},"di":{"value":"xxxxxxxxxxxxxxxxxxx"},"washerSpinLevel":{"value":"1600"},"mnsl":{"value":null},"dmv":{"value":"res.1.1.0,sh.1.1.0"},"washerRinseCycles":{"value":"2"},"vid":{"value":"DA-WM-WM-000001"},"completionTime":{"value":"2021-04-01T07:05:05Z"},"orderThreshold":{"value":"0","unit":"cc"},"supportedWasherWaterTemperature":{"value":"[\"none\",\"cold\",\"20\",\"30\",\"40\",\"60\",\"90\"]"},"supportedAmount":{"value":"[\"none\",\"less\",\"standard\",\"extra\"]"},"washerCycle":{"value":"Table_02_Course_1C"},"waterConsumption":{"value":null},"icv":{"value":"core.1.1.0"},"supportedWasherSpinLevel":{"value":"[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\",\"1600\"]"},"binaryId":{"value":"DA_WM_TP2_20_COMMON"},"serialNumber":{"value":null},"serialNumberExtra":{"value":null},"micomAssayCode":{"value":"20260041"},"mnmo":{"value":"DA_WM_TP2_20_COMMON|20260041|20010002001411E702A3020700000000"},"mnmn":{"value":"Samsung Electronics"},"maxNumberOfPresets":{"value":"10"},"mnml":{"value":"http://www.samsung.com"},"jobBeginningStatus":{"value":"None"},"supportedWaterValve":{"value":null},"remoteControlEnabled":{"value":"false"},"supportedWasherRinseCycles":{"value":"[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]"},"status":{"value":"off"},"supportedCourses":{"value":"[\"1C\",\"2B\",\"1B\",\"1E\",\"1D\",\"1F\",\"25\",\"26\",\"33\",\"24\",\"32\",\"20\",\"22\",\"23\",\"2F\",\"21\",\"2A\",\"2E\",\"2D\",\"30\",\"27\",\"28\",\"29\"]"},"dosage":{"value":"0","unit":"cc"},"mndt":{"value":null},"mnhw":{"value":"MediaTek"},"supportedWaterLevel":{"value":null},"description":{"value":"DA_WM_TP2_20_COMMON_WW6600R/DC92-02615A_3046"},"lockState":{"value":"unlocked"},"switch":{"value":"off"},"supportedCycles":{"value":"[{\"cycle\":\"1C\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"3500\",\"options\":[]},\"spinLevel\":{\"raw\":\"A7FF\",\"default\":\"1600\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\",\"1600\"]},\"rinseCycle\":{\"raw\":\"923F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"8410\",\"default\":\"40\",\"options\":[\"40\"]}}},{\"cycle\":\"2B\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"3500\",\"options\":[]},\"spinLevel\":{\"raw\":\"A67F\",\"default\":\"1400\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\"]},\"rinseCycle\":{\"raw\":\"9308\",\"default\":\"3\",\"options\":[\"3\"]},\"waterTemperature\":{\"raw\":\"8410\",\"default\":\"40\",\"options\":[\"40\"]}}},{\"cycle\":\"1B\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"35F0\",\"default\":\"off\",\"options\":[\"on\",\"off\"]},\"spinLevel\":{\"raw\":\"A7FF\",\"default\":\"1600\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\",\"1600\"]},\"rinseCycle\":{\"raw\":\"923F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"847E\",\"default\":\"40\",\"options\":[\"cold\",\"20\",\"30\",\"40\",\"60\",\"90\"]}}},{\"cycle\":\"1E\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"3500\",\"options\":[]},\"spinLevel\":{\"raw\":\"A33F\",\"default\":\"800\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\"]},\"rinseCycle\":{\"raw\":\"933F\",\"default\":\"3\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"811E\",\"default\":\"cold\",\"options\":[\"cold\",\"20\",\"30\",\"40\"]}}},{\"cycle\":\"1D\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"35F0\",\"default\":\"off\",\"options\":[\"on\",\"off\"]},\"spinLevel\":{\"raw\":\"A67F\",\"default\":\"1400\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\"]},\"rinseCycle\":{\"raw\":\"923F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"841E\",\"default\":\"40\",\"options\":[\"cold\",\"20\",\"30\",\"40\"]}}},{\"cycle\":\"1F\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"3500\",\"options\":[]},\"spinLevel\":{\"raw\":\"A57F\",\"default\":\"1200\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\"]},\"rinseCycle\":{\"raw\":\"923F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"8102\",\"default\":\"cold\",\"options\":[\"cold\"]}}},{\"cycle\":\"25\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"35F0\",\"default\":\"off\",\"options\":[\"on\",\"off\"]},\"spinLevel\":{\"raw\":\"A57F\",\"default\":\"1200\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\"]},\"rinseCycle\":{\"raw\":\"923F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"843E\",\"default\":\"40\",\"options\":[\"cold\",\"20\",\"30\",\"40\",\"60\"]}}},{\"cycle\":\"26\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"3500\",\"options\":[]},\"spinLevel\":{\"raw\":\"A30F\",\"default\":\"800\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\"]},\"rinseCycle\":{\"raw\":\"920F\",\"default\":\"2\",\"options\":[\"0\",\"1\",\"2\",\"3\"]},\"waterTemperature\":{\"raw\":\"831E\",\"default\":\"30\",\"options\":[\"cold\",\"20\",\"30\",\"40\"]}}},{\"cycle\":\"33\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"35F0\",\"default\":\"off\",\"options\":[\"on\",\"off\"]},\"spinLevel\":{\"raw\":\"A67F\",\"default\":\"1400\",\"options\":[\"rinseHold\",\"noSpin\",\"400\",\"800\",\"1000\",\"1200\",\"1400\"]},\"rinseCycle\":{\"raw\":\"933F\",\"default\":\"3\",\"options\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\"]},\"waterTemperature\":{\"raw\":\"857E\",\"default\":\"60\",\"options\":[\"cold\",\"20\",\"30\",\"40\",\"60\",\"90\"]}}},{\"cycle\":\"24\",\"supportedOptions\":{\"bubbleSoak\":{\"raw\":\"35F0\",\"default\":\"off\",\"options\":[\"on\",\"off\"]},\"spinLevel
Dryer:

Code: Select all

2021-04-01 16:30:57.847 Status: dzVents: !Info: SamsungWashingMachines: {"main":{"mnfv":{"value":"DA_WM_TP2_20_COMMON_30210226"},"data":{"value":"{\"payload\":{\"rt\":[\"x.com.samsung.da.rm.wifi\"],\"if\":[\"oic.if.baseline\",\"oic.if.s\"],\"x.com.samsung.rm.rssi\":[-60]}}"},"di":{"value":"xxxxxxxxxxxxxxxxx"},"mnsl":{"value":null},"dmv":{"value":"1.2.1"},"vid":{"value":"DA-WM-WD-000001"},"completionTime":{"value":"2021-04-01T12:03:21Z"},"orderThreshold":{"value":"0","unit":"cc"},"icv":{"value":"core.1.1.0"},"dryerWrinklePrevent":{"value":"off"},"binaryId":{"value":null},"serialNumber":{"value":null},"serialNumberExtra":{"value":null},"micomAssayCode":{"value":null},"mnmo":{"value":"DA_WM_TP2_20_COMMON|20262941|300101020014110002A3030700000000"},"mnmn":{"value":"Samsung Electronics"},"maxNumberOfPresets":{"value":null},"mnml":{"value":"http://www.samsung.com"},"jobBeginningStatus":{"value":"None"},"remoteControlEnabled":{"value":"false"},"supportedCourses":{"value":"[\"16\",\"23\",\"17\",\"1F\",\"18\",\"19\",\"1D\",\"1B\",\"1C\",\"21\",\"1A\",\"1E\",\"20\",\"27\",\"25\",\"24\",\"26\"]"},"dosage":{"value":"0","unit":"cc"},"mndt":{"value":null},"mnhw":{"value":"MediaTek"},"dryingTemperature":{"value":null},"description":{"value":null},"dryingTime":{"value":null,"unit":"min"},"lockState":{"value":"unlocked"},"dryerJobState":{"value":"none"},"switch":{"value":"off"},"supportedCycles":{"value":"[{\"cycle\":\"16\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"23\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"17\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1F\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"18\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"19\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1D\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1B\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1C\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"21\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D308\",\"options\":[]}}},{\"cycle\":\"1A\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D102\",\"options\":[]}}},{\"cycle\":\"1E\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"20\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D102\",\"options\":[]}}},{\"cycle\":\"27\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"25\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"24\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"26\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D10E\",\"options\":[]}}}]"},"remainingAmount":{"value":"0","unit":"cc"},"mnpv":{"value":"DAWIT 2.0"},"dryerDryLevel":{"value":"2"},"supportedDryingTemperature":{"value":null},"referenceTable":{"value":"{\"id\":\"Table_03\"}"},"st":{"value":null},"powerConsumption":{"value":"{\"energy\":5600,\"deltaEnergy\":0,\"power\":0,\"powerEnergy\":0.0,\"persistedEnergy\":0,\"energySaved\":0,\"start\":\"2021-04-01T08:22:38Z\",\"end\":\"2021-04-01T08:23:14Z\"}"},"machineState":{"value":"stop"},"disabledCapabilities":{"value":"[\"samsungce.dryerDryingTemperature\",\"samsungce.welcomeMessage\"]"},"modelClassificationCode":{"value":null},"welcomeMessage":{"value":null},"supportedDryerDryLevel":{"value":"[\"none\",\"1\",\"2\",\"3\"]"},"dryerAutoCycleLink":{"value":"off"},"n":{"value":"[dryer] Samsung"},"versionNumber":{"value":"21030301"},"alarmEnabled":{"value":"false"},"dryerCycle":{"value":"Table_03_Course_16"},"modelName":{"value":null},"presets":{"value":null},"mnos":{"value":"TizenRT 1.0 + IPv6"},"initialAmount":{"value":"0","unit":"cc"},"supportedDryingTime":{"value":null},"detergentType":{"value":null},"pi":{"value":"xxxxxxxxxxxxxxxxx"},"supportedMachineStates":{"value":null}}}
I must say that I appreciate your contribution! I try to do my part in helping others with this "debugging exersice" as well :) Somehow it seem to work in my place where it should not.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Thursday 01 April 2021 16:32 I must say that I appreciate your contribution! I try to do my part in helping others with this "debugging exersice" as well :) Somehow it seem to work in my place where it should not.
Thanx for the log.

My persistent attention for this issue is because I want dzVents in the next stable release to be able to deal with all kinds of data, even when that data does not fully comply with RFC standards.

Tested successfully with the data you supplied, the new function deSerializeJSON() prepares the json string to be converted in a Lua table in one pass.
I would be much obliged if you could test below version and report back your findings.

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)

        -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end

        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

                item.json = dz.utils.fromJSON(deSerializeJSON(item.data)) -- again after deserializing the nested JSON 
                rt = item.json.main
                local endProgram = 'No active program'

                -- local values = dz.utils.fromJSON(item.json.main.data.value) -- should no longer be needed?

                local values = 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Thursday 01 April 2021 21:52
Robinjoo94 wrote: Thursday 01 April 2021 16:32 I must say that I appreciate your contribution! I try to do my part in helping others with this "debugging exersice" as well :) Somehow it seem to work in my place where it should not.
Thanx for the log.

My persistent attention for this issue is because I want dzVents in the next stable release to be able to deal with all kinds of data, even when that data does not fully comply with RFC standards.

Tested successfully with the data you supplied, the new function deSerializeJSON() prepares the json string to be converted in a Lua table in one pass.
I would be much obliged if you could test below version and report back your findings.

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)

        -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end

        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

                item.json = dz.utils.fromJSON(deSerializeJSON(item.data)) -- again after deserializing the nested JSON 
                rt = item.json.main
                local endProgram = 'No active program'

                -- local values = dz.utils.fromJSON(item.json.main.data.value) -- should no longer be needed?

                local values = 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
}

Code: Select all

2021-04-02 08:56:01.427 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: expected string's opening quote at byte 75 of: {"main":{"mnfv":{"value":"DA_WM_TP2_20_COMMON_30210226"},"data":{"value":{\"payload\":{\"rt\":[\"x.com.samsung.da.rm.wifi\"],\"if\":[\"oic.if.baseline\",\"oic.if.s\"],\"x.com.samsung.rm.rssi\":[-60]}}},"di":{"value":"xxxxxxxxxxx"},"mnsl":{"value":null},"dmv":{"value":"1.2.1"},"vid":{"value":"DA-WM-WD-000001"},"completionTime":{"value":"2021-04-01T12:03:21Z"},"orderThreshold":{"value":"0","unit":"cc"},"icv":{"value":"core.1.1.0"},"dryerWrinklePrevent":{"value":"off"},"binaryId":{"value":null},"serialNumber":{"value":null},"serialNumberExtra":{"value":null},"micomAssayCode":{"value":null},"mnmo":{"value":"DA_WM_TP2_20_COMMON|20262941|300101020014110002A3030700000000"},"mnmn":{"value":"Samsung Electronics"},"maxNumberOfPresets":{"value":null},"mnml":{"value":"http://www.samsung.com"},"jobBeginningStatus":{"value":"None"},"remoteControlEnabled":{"value":"false"},"supportedCourses":{"value":"[\"16\",\"23\",\"17\",\"1F\",\"18\",\"19\",\"1D\",\"1B\",\"1C\",\"21\",\"1A\",\"1E\",\"20\",\"27\",\"25\",\"24\",\"26\"]},"dosage":{"value":"0","unit":"cc"},"mndt":{"value":null},"mnhw":{"value":"MediaTek"},"dryingTemperature":{"value":null},"description":{"value":null},"dryingTime":{"value":null,"unit":"min"},"lockState":{"value":"unlocked"},"dryerJobState":{"value":"none"},"switch":{"value":"off"},"supportedCycles":{"value":"[{\"cycle\":\"16\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"23\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"17\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1F\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"18\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"19\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1D\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1B\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"1C\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D20E\",\"options\":[]}}},{\"cycle\":\"21\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D308\",\"options\":[]}}},{\"cycle\":\"1A\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D102\",\"options\":[]}}},{\"cycle\":\"1E\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D204\",\"options\":[]}}},{\"cycle\":\"20\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D102\",\"options\":[]}}},{\"cycle\":\"27\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"25\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"24\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D000\",\"options\":[]}}},{\"cycle\":\"26\",\"supportedOptions\":{\"dryingLevel\":{\"raw\":\"D10E\",\"options\":[]}}}]},"remainingAmount":{"value":"0","unit":"cc"},"mnpv":{"value":"DAWIT 2.0"},"dryerDryLevel":{"value":"2"},"supportedDryingTemperature":{"value":null},"referenceTable":{"value":{\"id\":\"Table_03\"}},"st":{"value":null},"powerConsumption":{"value":{\"energy\":5600,\"deltaEnergy\":0,\"power\":0,\"powerEnergy\":0.0,\"persistedEnergy\":0,\"energySaved\":0,\"start\":\"2021-04-01T08:22:38Z\",\"end\":\"2021-04-01T08:23:14Z\"}},"machineState":{"value":"stop"},"disabledCapabilities":{"value":"[\"samsungce.dryerDryingTemperature\",\"samsungce.welcomeMessage\"]},"modelClassificationCode":{"value":null},"welcomeMessage":{"value":null},"supportedDryerDryLevel":{"value":"[\"none\",\"1\",\"2\",\"3\"]},"dryerAutoCycleLink":{"value":"off"},"n":{"value":"[dryer] Samsung"},"versionNumber":{"value":"21030301"},"alarmEnabled":{"value":"false"},"dryerCycle":{"value":"Table_03_Course_16"},"modelName":{"value":null},"presets":{"value":null},"mnos":{"value":"TizenRT 1.0 + IPv6"},"initialAmount":{"value":"0","unit":"cc"},"supportedDryingTime":{"value":null},"detergentType":{"value":null},"pi":{"value":"xxxxxxxxxxxxx"},"supportedMachineStates":{"value":null}}}
2021-04-02 08:56:01.427 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: An error occurred when calling event handler Samsung
2021-04-02 08:56:01.428 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: ...i/domoticz/scripts/dzVents/generated_scripts/Samsung.lua:207: attempt to index a number value (field 'json')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Friday 02 April 2021 8:58

Code: Select all

2021-04-02 08:56:01.427 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: An error occurred when calling event handler Samsung
2021-04-02 08:56:01.428 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: ...i/domoticz/scripts/dzVents/generated_scripts/Samsung.lua:207: attempt to index a number value (field 'json')
Thx.
Last try.

Can you change

Code: Select all

        -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end
to

Code: Select all

       -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}'):gsub('\"','"')
        end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

waaren wrote: Friday 02 April 2021 9:27
Robinjoo94 wrote: Friday 02 April 2021 8:58

Code: Select all

2021-04-02 08:56:01.427 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: An error occurred when calling event handler Samsung
2021-04-02 08:56:01.428 Error: dzVents: Error: (3.0.2) SamsungWashingMachines: ...i/domoticz/scripts/dzVents/generated_scripts/Samsung.lua:207: attempt to index a number value (field 'json')
Thx.
Last try.

Can you change

Code: Select all

        -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end
to

Code: Select all

       -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}'):gsub('\"','"')
        end
I did some debugging myself, order of the above had to change a bit due and I had to escape the backslash with a backslash (annoying, single quote does the trick in perl...).
But now it is functional like this:

Code: Select all

       -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('\\"','"'):gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end
I will post the entire code later today...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

Robinjoo94 wrote: Friday 02 April 2021 9:58 I did some debugging myself, order of the above had to change a bit due and I had to escape the backslash with a backslash (annoying, single quote does the trick in perl...).
But now it is functional like this:

Code: Select all

       -- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
        local function deSerializeJSON(json)
            return json:gsub('\\"','"'):gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
        end
👍 Thanx for testing and improving the function. Much appreciated !!
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dizzeenl
Posts: 31
Joined: Wednesday 14 November 2018 23:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Dordrecht
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by dizzeenl »

I couldn't imagine that my post started this reaction to solve this piece :D . Can't wait to run a new wash :lol:

Thanks again, i will test it soon
Robinjoo94
Posts: 21
Joined: Saturday 25 May 2019 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by Robinjoo94 »

So the combined code with the working Daylight Saving Time handling and the JSON deserialization functions waaren suggested:

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})
	
	local tmp_time = os.time()
	local d1 = os.date("*t",  tmp_time)
	local d2 = os.date("!*t", tmp_time)
	d1.isdst = false
	local zone_diff = os.difftime(os.time(d1), os.time(d2))
	return os.date('%H:%M:%S', convertedTimestamp + zone_diff)
end

-- This function should make a nested (serialized) JSON behave like a normal one when converted to a Lua table
local function deSerializeJSON(json)
	return json:gsub('\\"','"'):gsub('"{','{'):gsub('"%["','["'):gsub('"%]"','"]'):gsub('}"','}'):gsub('"%[{"','[{"'):gsub('"}%]"','"}]'):gsub('%]"}',']}')
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
				
				-- again after deserializing the nested JSON 
				item.json = dz.utils.fromJSON(deSerializeJSON(item.data))
                rt = item.json.main
				
				local endProgram = 'No active program'
				local values = 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
}
dizzeenl
Posts: 31
Joined: Wednesday 14 November 2018 23:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Dordrecht
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by dizzeenl »

When i use your last code i still get the error

Code: Select all

2021-04-05 22:47:00.995 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: An error occurred when calling event handler 09 SAMSUNG WASHDRY
2021-04-05 22:47:00.995 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: ...scripts/dzVents/generated_scripts/09 SAMSUNG WASHDRY.lua:218: attempt to index a nil value (local 'values')
Even when i change the "nested (serialized) JSON" on line 158 to the waaren's version the error contineus. if i know how to share a log or something please let met know (how to do it :lol: )
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

dizzeenl wrote: Monday 05 April 2021 22:50 Even when i change the "nested (serialized) JSON" on line 158 to the waaren's version the error contineus. if i know how to share a log or something please let met know (how to do it :lol: )
Can you Insert below at line 211 and share the log?

Code: Select all

dz.utils.dumpTable(item.json)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dizzeenl
Posts: 31
Joined: Wednesday 14 November 2018 23:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Dordrecht
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by dizzeenl »

Code: Select all

2021-04-06 09:43:00.481 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-04-06 09:43:00.869 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-04-06 09:43:00.918 Status: dzVents: Debug: dzVents version: 3.1.7
2021-04-06 09:43:00.918 Status: dzVents: Debug: Event triggers:
2021-04-06 09:43:00.918 Status: dzVents: Debug: - HTTPResponse: WashingMachine
2021-04-06 09:43:00.974 Status: dzVents: Info: Handling httpResponse-events for: "WashingMachine"
2021-04-06 09:43:00.976 Status: dzVents: > main:
2021-04-06 09:43:00.976 Status: dzVents: > machineState:
2021-04-06 09:43:00.976 Status: dzVents: > value: stop
2021-04-06 09:43:00.976 Status: dzVents: > dmv:
2021-04-06 09:43:00.976 Status: dzVents: > value: res.1.1.0,sh.1.1.0
2021-04-06 09:43:00.976 Status: dzVents: > mnsl:
2021-04-06 09:43:00.976 Status: dzVents: > n:
2021-04-06 09:43:00.976 Status: dzVents: > value: Wasmachine
2021-04-06 09:43:00.976 Status: dzVents: > data:
2021-04-06 09:43:00.976 Status: dzVents: > mndt:
2021-04-06 09:43:00.976 Status: dzVents: > switch:
2021-04-06 09:43:00.976 Status: dzVents: > mnmn:
2021-04-06 09:43:00.977 Status: dzVents: > value: Samsung Electronics
2021-04-06 09:43:00.977 Status: dzVents: > mnml:
2021-04-06 09:43:00.977 Status: dzVents: > versionNumber:
2021-04-06 09:43:00.977 Status: dzVents: > value: 21032501
2021-04-06 09:43:00.977 Status: dzVents: > mnpv:
2021-04-06 09:43:00.977 Status: dzVents: > di:
2021-04-06 09:43:00.977 Status: dzVents: > value: C0972780-****-0000-0000-000000000000
2021-04-06 09:43:00.977 Status: dzVents: > icv:
2021-04-06 09:43:00.977 Status: dzVents: > value: core.1.1.0
2021-04-06 09:43:00.977 Status: dzVents: > mnfv:
2021-04-06 09:43:00.977 Status: dzVents: > washerJobState:
2021-04-06 09:43:00.977 Status: dzVents: > value: none
2021-04-06 09:43:00.977 Status: dzVents: > remoteControlEnabled:
2021-04-06 09:43:00.977 Status: dzVents: > value: false
2021-04-06 09:43:00.977 Status: dzVents: > pi:
2021-04-06 09:43:00.977 Status: dzVents: > value: shp
2021-04-06 09:43:00.977 Status: dzVents: > mnos:
2021-04-06 09:43:00.977 Status: dzVents: > st:
2021-04-06 09:43:00.977 Status: dzVents: > completionTime:
2021-04-06 09:43:00.977 Status: dzVents: > value: 2021-04-03T00:06:14Z
2021-04-06 09:43:00.977 Status: dzVents: > supportedMachineStates:
2021-04-06 09:43:00.977 Status: dzVents: > mnmo:
2021-04-06 09:43:00.977 Status: dzVents: > value: TP6X_WW7500
2021-04-06 09:43:00.977 Status: dzVents: > vid:
2021-04-06 09:43:00.977 Status: dzVents: > value: DA-WM-WM-100001
2021-04-06 09:43:00.977 Status: dzVents: > mnhw:
2021-04-06 09:43:00.979 Status: dzVents: !Info: SamsungWashingMachines: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-04-06 09:43:00.979 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: An error occurred when calling event handler 09 SAMSUNG WASHDRY
2021-04-06 09:43:00.979 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: ...scripts/dzVents/generated_scripts/09 SAMSUNG WASHDRY.lua:218: attempt to index a nil value (local 'values')
2021-04-06 09:43:01.028 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-04-06 09:43:01.077 Status: dzVents: Debug: dzVents version: 3.1.7
2021-04-06 09:43:01.077 Status: dzVents: Debug: Event triggers:
2021-04-06 09:43:01.077 Status: dzVents: Debug: - HTTPResponse: Dryer
2021-04-06 09:43:01.134 Status: dzVents: Info: Handling httpResponse-events for: "Dryer"
2021-04-06 09:43:01.136 Status: dzVents: > main:
2021-04-06 09:43:01.136 Status: dzVents: > machineState:
2021-04-06 09:43:01.136 Status: dzVents: > value: stop
2021-04-06 09:43:01.136 Status: dzVents: > dmv:
2021-04-06 09:43:01.136 Status: dzVents: > value: res.1.1.0,sh.1.1.0
2021-04-06 09:43:01.136 Status: dzVents: > mnsl:
2021-04-06 09:43:01.136 Status: dzVents: > n:
2021-04-06 09:43:01.136 Status: dzVents: > value: Droger
2021-04-06 09:43:01.136 Status: dzVents: > data:
2021-04-06 09:43:01.136 Status: dzVents: > mndt:
2021-04-06 09:43:01.136 Status: dzVents: > switch:
2021-04-06 09:43:01.136 Status: dzVents: > dryerJobState:
2021-04-06 09:43:01.136 Status: dzVents: > value: none
2021-04-06 09:43:01.136 Status: dzVents: > mnml:
2021-04-06 09:43:01.136 Status: dzVents: > versionNumber:
2021-04-06 09:43:01.136 Status: dzVents: > value: 20061501
2021-04-06 09:43:01.136 Status: dzVents: > mnpv:
2021-04-06 09:43:01.136 Status: dzVents: > di:
2021-04-06 09:43:01.136 Status: dzVents: > value: C0972786-****-0000-0000-000000000000
2021-04-06 09:43:01.136 Status: dzVents: > icv:
2021-04-06 09:43:01.136 Status: dzVents: > value: core.1.1.0
2021-04-06 09:43:01.136 Status: dzVents: > st:
2021-04-06 09:43:01.137 Status: dzVents: > remoteControlEnabled:
2021-04-06 09:43:01.137 Status: dzVents: > value: false
2021-04-06 09:43:01.137 Status: dzVents: > pi:
2021-04-06 09:43:01.137 Status: dzVents: > value: shp
2021-04-06 09:43:01.137 Status: dzVents: > mnos:
2021-04-06 09:43:01.137 Status: dzVents: > completionTime:
2021-04-06 09:43:01.137 Status: dzVents: > value: 2021-01-16T08:38:50.293Z
2021-04-06 09:43:01.137 Status: dzVents: > mnfv:
2021-04-06 09:43:01.137 Status: dzVents: > mnmn:
2021-04-06 09:43:01.137 Status: dzVents: > value: Samsung Electronics
2021-04-06 09:43:01.137 Status: dzVents: > supportedMachineStates:
2021-04-06 09:43:01.137 Status: dzVents: > mnmo:
2021-04-06 09:43:01.137 Status: dzVents: > value: TP6X_DV80M8214AW|20183944|30010102001111000100000000000000
2021-04-06 09:43:01.137 Status: dzVents: > vid:
2021-04-06 09:43:01.137 Status: dzVents: > value: DA-WM-WD-100001
2021-04-06 09:43:01.137 Status: dzVents: > mnhw:
2021-04-06 09:43:01.139 Status: dzVents: !Info: SamsungWashingMachines: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-04-06 09:43:01.139 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: An error occurred when calling event handler 09 SAMSUNG WASHDRY
2021-04-06 09:43:01.139 Error: dzVents: Error: (3.1.7) SamsungWashingMachines: ...scripts/dzVents/generated_scripts/09 SAMSUNG WASHDRY.lua:218: attempt to index a nil value (local 'values')
2021-04-06 09:43:31.643 Buienradar: General/Custom Sensor (Next Rainshower Leadtime)
2021-04-06 09:43:31.732 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-04-06 09:43:31.820 Status: dzVents: Debug: Processing device-adapter for Next Rainshower Leadtime: Custom sensor device adapter
2021-04-06 09:43:31.821 Status: dzVents: Debug: dzVents version: 3.1.7
2021-04-06 09:43:31.821 Status: dzVents: Debug: Event triggers:
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Samsung Washmachine read status from json "SOLVED"

Post by waaren »

dizzeenl wrote: Tuesday 06 April 2021 9:45 2021-04-06 09:43:00.974 Status: dzVents: Info: Handling httpResponse-events for: "WashingMachine"
This data does not look like anything close to that from @Tjeerd13 and @Robinjoo94
I don't own the Samsung machines myself so kind of hard to see what causes this.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest