Easy to use, 100% Lua-based event scripting framework.
Moderator: leecollings
jannnfe
Posts: 30 Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:
Post
by jannnfe » Wednesday 26 September 2018 0:21
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
dannybloe
Posts: 1355 Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:
Post
by dannybloe » Wednesday 26 September 2018 7:04
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).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jannnfe
Posts: 30 Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:
Post
by jannnfe » Wednesday 26 September 2018 10:54
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
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Wednesday 26 September 2018 15:00
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
jannnfe
Posts: 30 Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:
Post
by jannnfe » Wednesday 26 September 2018 16:42
Thanks @waaren,
the item.rawData[1] was the solution i was searching!
With this i get the "Test" value.
Thank you very much!
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Wednesday 26 September 2018 18:35
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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
jannnfe
Posts: 30 Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:
Post
by jannnfe » 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:
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
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Wednesday 26 September 2018 20:19
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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
Users browsing this forum: No registered users and 1 guest