Page 1 of 1
Get sValue from device
Posted: Wednesday 26 September 2018 0:21
by jannnfe
Hello,
is there a way to get the value from a device?
I tried:
Code: Select all
return {
on = {
devices = {
'Kamera Motion Dummy'
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'CameraMotion'
},
execute = function(domoticz, item)
-- When Device is triggered do this:
if(item.isDevice) then
if(item.active) then
local device = item.status
domoticz.log(device, domoticz.LOG_DEBUG)
end
end
end
}
Thanks

Re: Get sValue from device
Posted: Wednesday 26 September 2018 7:04
by dannybloe
First of all, you don't need to test for isDevice in your case here because your event trigger is only for a device. But that's a side note. To get the value of the device (in this case a motion detector I suppose) I assume that you can just print the state: domoticz.log(device.state).
Re: Get sValue from device
Posted: Wednesday 26 September 2018 10:54
by jannnfe
Hallo @dannybloe,
Thanks for your reply.
I dont understand. device.state? Do you mean item.state?
I already tested this. But the state (or „svalue“) is different. I Set a the device over MQTT like this: {„idx“:124,“nvalue“:1,“svalue“:“Test“}
I want to get the „Test“ from svalue. But with item.state i will get the value „On“.
Thank you

Re: Get sValue from device
Posted: Wednesday 26 September 2018 15:00
by waaren
jannnfe wrote: ↑Wednesday 26 September 2018 10:54
I dont understand. device.state? Do you mean item.state?
I already tested this. But the state (or „svalue“) is different. I Set a the device over MQTT like this: {„idx“:124,“nvalue“:1,“svalue“:“Test“}
I want to get the „Test“ from svalue. But with item.state i will get the value „On“.
Thank you
maybe this will help you understand and see what the state of your device is
Code: Select all
return {
on = {
devices = {
'Kamera Motion Dummy'
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'CameraMotion'
},
execute = function(domoticz, item)
-- When Device is triggered do this:
local activeState = " (not Active) "
if item.active then
activeState = " (Active) "
domoticz.log("Status of " .. item.name .. " ===>> " .. item.state, domoticz.LOG_DEBUG)
end
local rawData = item.rawData
for i = 1,#rawData do
domoticz.log(activeState .. " " .. item.name .. ".rawData[" .. i .."] ==>> " .. item.rawData[i], domoticz.LOG_DEBUG)
end
end
}
Re: Get sValue from device [Solved]
Posted: Wednesday 26 September 2018 16:42
by jannnfe
Thanks @waaren,
the item.rawData[1] was the solution i was searching!
With this i get the "Test" value.
Thank you very much!

Re: Get sValue from device
Posted: Wednesday 26 September 2018 18:35
by waaren
jannnfe wrote: ↑Wednesday 26 September 2018 16:42
the item.rawData[1] was the solution i was searching! With this i get the "Test" value.
Ok. Now we know the value 'Test' is somewhere in the device object, there is probably a more elegant place where we can get it from.
can you replace the code
Code: Select all
local rawData = item.rawData
for i = 1,#rawData do
domoticz.log(activeState .. " " .. item.name .. ".rawData[" .. i .."] ==>> " .. item.rawData[i], domoticz.LOG_DEBUG)
end
with
and post the result here ?
Re: Get sValue from device
Posted: Wednesday 26 September 2018 19:07
by jannnfe
Hey,
Yes, that's the result. It looks like there is something missing due to log limitations but the relevant part is there:
Now the value to be searched is not "Test" but "Eingang"!
It is in rawData 1.
Code: Select all
2018-09-26 18:58:53.441 Status: dzVents: > yday: 269
2018-09-26 18:58:53.441 Status: dzVents: > year: 2018
2018-09-26 18:58:53.441 Status: dzVents: > rawTime: 18:58:03
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtSunrise()
2018-09-26 18:58:53.441 Status: dzVents: > ruleMatchesHourSpecification()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtDayTime()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtNight()
2018-09-26 18:58:53.441 Status: dzVents: > week: 39
2018-09-26 18:58:53.441 Status: dzVents: > current:
2018-09-26 18:58:53.441 Status: dzVents: > hour: 18
2018-09-26 18:58:53.441 Status: dzVents: > day: 26
2018-09-26 18:58:53.441 Status: dzVents: > year: 2018
2018-09-26 18:58:53.441 Status: dzVents: > wday: 4
2018-09-26 18:58:53.441 Status: dzVents: > month: 9
2018-09-26 18:58:53.441 Status: dzVents: > sec: 53
2018-09-26 18:58:53.441 Status: dzVents: > isdst: true
2018-09-26 18:58:53.441 Status: dzVents: > yday: 269
2018-09-26 18:58:53.441 Status: dzVents: > min: 58
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtCivilNight()
2018-09-26 18:58:53.441 Status: dzVents: > sec: 3
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsOnDate()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAfterCivilTwilightStart()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAfterSunrise()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsOnDay()
2018-09-26 18:58:53.441 Status: dzVents: > day: 26
2018-09-26 18:58:53.441 Status: dzVents: > raw: 2018-09-26 18:58:03
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAfterSunset()
2018-09-26 18:58:53.441 Status: dzVents: > minutes: 58
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtSunset()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsBeforeSunrise()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAfterCivilTwilightEnd()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsBeforeCivilTwilightEnd()
2018-09-26 18:58:53.441 Status: dzVents: > isToday: true
2018-09-26 18:58:53.441 Status: dzVents: > daysAgo: 0
2018-09-26 18:58:53.441 Status: dzVents: > minutesAgo: 0
2018-09-26 18:58:53.441 Status: dzVents: > isUTC: false
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsInWeek()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtCivilTwilightStart()
2018-09-26 18:58:53.441 Status: dzVents: > min: 58
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsBeforeCivilTwilightStart()
2018-09-26 18:58:53.441 Status: dzVents: > getISO()
2018-09-26 18:58:53.441 Status: dzVents: > milliseconds: 0
2018-09-26 18:58:53.441 Status: dzVents: > rawDate: 2018-09-26
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsBeforeSunset()
2018-09-26 18:58:53.441 Status: dzVents: > compare()
2018-09-26 18:58:53.441 Status: dzVents: > hoursAgo: 0
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtCivilDayTime()
2018-09-26 18:58:53.441 Status: dzVents: > ruleIsAtCivilTwilightEnd()
2018-09-26 18:58:53.441 Status: dzVents: > utils:
2018-09-26 18:58:53.441 Status: dzVents: > rgbToHSB()
2018-09-26 18:58:53.441 Status: dzVents: > fileExists()
2018-09-26 18:58:53.441 Status: dzVents: > LOG_MODULE_EXEC_INFO: 2
2018-09-26 18:58:53.441 Status: dzVents: > LOG_DEBUG: 4
2018-09-26 18:58:53.441 Status: dzVents: > LOG_INFO: 3
2018-09-26 18:58:53.441 Status: dzVents: > log()
2018-09-26 18:58:53.441 Status: dzVents: > toJSON()
2018-09-26 18:58:53.441 Status: dzVents: > osExecute()
2018-09-26 18:58:53.441 Status: dzVents: > print()
2018-09-26 18:58:53.441 Status: dzVents: > urlEncode()
2018-09-26 18:58:53.441 Status: dzVents: > LOG_FORCE: 0.5
2018-09-26 18:58:53.441 Status: dzVents: > LOG_ERROR: 1
2018-09-26 18:58:53.441 Status: dzVents: > fromJSON()
2018-09-26 18:58:53.441 Status: dzVents: > wday: 4
2018-09-26 18:58:53.441 Status: dzVents: > secondsAgo: 50
2018-09-26 18:58:53.441 Status: dzVents: > msAgo: 50402
2018-09-26 18:58:53.441 Status: dzVents: > isdst: true
2018-09-26 18:58:53.441 Status: dzVents: > millisecondsAgo: 50402
2018-09-26 18:58:53.441 Status: dzVents: > dayAbbrOfWeek: wed
2018-09-26 18:58:53.441 Status: dzVents: > updateWaterflow()
2018-09-26 18:58:53.441 Status: dzVents: > updateSoundLevel()
2018-09-26 18:58:53.441 Status: dzVents: > updateVoltage()
2018-09-26 18:58:53.441 Status: dzVents: > id: 124
2018-09-26 18:58:53.441 Status: dzVents: > signalLevel: 6
2018-09-26 18:58:53.441 Status: dzVents: > isVariable: false
2018-09-26 18:58:53.441 Status: dzVents: > description:
2018-09-26 18:58:53.441 Status: dzVents: > hardwareName: Virtual Device
2018-09-26 18:58:53.441 Status: dzVents: > update()
2018-09-26 18:58:53.441 Status: dzVents: > updateLux()
2018-09-26 18:58:53.441 Status: dzVents: > kodiExecuteAddOn()
2018-09-26 18:58:53.441 Status: dzVents: > playFavorites()
2018-09-26 18:58:53.441 Status: dzVents: > hardwareTypeValue: 15
2018-09-26 18:58:53.441 Status: dzVents: > isHTTPResponse: false
2018-09-26 18:58:53.441 Status: dzVents: > _state: On
2018-09-26 18:58:53.441 Status: dzVents: > batteryLevel: 57
2018-09-26 18:58:53.441 Status: dzVents: > switchOff()
2018-09-26 18:58:53.441 Status: dzVents: > isSecurity: false
2018-09-26 18:58:53.441 Status: dzVents: > maxDimLevel: 100
2018-09-26 18:58:53.441 Status: dzVents: > updateElectricity()
2018-09-26 18:58:53.442 Status: dzVents: > rawData:
2018-09-26 18:58:53.442 Status: dzVents: > 1: Eingang
2018-09-26 18:58:53.442 Status: dzVents: > updateGas()
2018-09-26 18:58:53.442 Status: dzVents: > updatePercentage()
2018-09-26 18:58:53.442 Status: dzVents: > updatePressure()
2018-09-26 18:58:53.442 Status: dzVents: > kodiPause()
2018-09-26 18:58:53.442 Status: dzVents: Info: CameraMotion: ------ Finished CameraMotionSensor
I have set the device with MQTT and following payload:
Code: Select all
MQTT: Topic: domoticz/in, Message: {"RSSI":6,"idx":124,"Battery":57,"nvalue":1,"svalue":"Eingang"}
I do not know if there is an elegant way in the device object to pass the value "Eingang" via MQTT but that's how it worked
Thanks

Re: Get sValue from device
Posted: Wednesday 26 September 2018 20:19
by waaren
jannnfe wrote: ↑Wednesday 26 September 2018 19:07
Hey,
Yes, that's the result. It looks like there is something missing due to log limitations but the relevant part is there:
Indeed a lot of the relevant information from the dump() method is missing. What are the type / subType values for this device as shown in the devices tab ?