Hi,
I started working with dcVents a couple of days ago. I love it, but I want to do something with reading a devices attributes and don't know how to.
In a function, I parse through a variable with the names of devices I want to read. That works well, but from some devices I want to read the state and from others I like to read a value like current or color or whatever.
So, I read the devices description and in the first line, I wrote the name of the attribute I need to read.
Lets assume I have a switch named Switch1, of which I want to read the nValue.
I can turn the string 'Switch1' into a device with MyDevice = domoticz.devices('Switch1')
When I read the descriptiption I can put the desired attribute into another string like MyAttrib = MyDevice.description. That works fine, but MyAttrib is not a real attribute, so MyValue=MyDevice.MyAttrib does not work.
Is this possible at all?
Thanks,
Bert
How can I use a string as an attribute.
Moderator: leecollings
-
BertB
- Posts: 72
- Joined: Tuesday 24 June 2014 19:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: struggling and stumbling. Amsterdam area
- Contact:
How can I use a string as an attribute.
Set 1= RPI 3B, latest Beta, RFLink USB, RFLINK WIFI, Zwave
Set 2= RPI 2B, Latest Beta, OTGW (USB), SBFSpot (Bluetooth)
Set 2= RPI 2B, Latest Beta, OTGW (USB), SBFSpot (Bluetooth)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How can I use a string as an attribute.
@Bertb,BertB wrote: Saturday 11 August 2018 16:50 Hi,
I started working with dcVents a couple of days ago. I love it, but I want to do something with reading a devices attributes and don't know how to.
In a function, I parse through a variable with the names of devices I want to read. That works well, but from some devices I want to read the state and from others I like to read a value like current or color or whatever.
So, I read the devices description and in the first line, I wrote the name of the attribute I need to read.
Lets assume I have a switch named Switch1, of which I want to read the nValue.
I can turn the string 'Switch1' into a device with MyDevice = domoticz.devices('Switch1')
When I read the descriptiption I can put the desired attribute into another string like. That works fine, but MyAttrib is not a real attribute, so MyValue=MyDevice.MyAttrib does not work.Code: Select all
MyAttrib = MyDevice.description
Is this possible at all?
Thanks,
Bert
Your MyDevice is a lua table with all attribute names as keys.
So the correct syntax for your requirement is
Code: Select all
MyDevice = domoticz.devices('Switch1')
MyAttrib = MyDevice.description
MyValue = MyDevice[MyAttrib]
Code: Select all
return {
on = {
timer = { 'every minute'
}},
execute = function(dz)
local sensor = dz.devices('temperatuur Rotterdam')
local attribute = "temperature"
dz.log(sensor[attribute])
end
}Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
BertB
- Posts: 72
- Joined: Tuesday 24 June 2014 19:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: struggling and stumbling. Amsterdam area
- Contact:
Re: How can I use a string as an attribute.
Thank you so mutch for pointing me in the right direction
Set 1= RPI 3B, latest Beta, RFLink USB, RFLINK WIFI, Zwave
Set 2= RPI 2B, Latest Beta, OTGW (USB), SBFSpot (Bluetooth)
Set 2= RPI 2B, Latest Beta, OTGW (USB), SBFSpot (Bluetooth)
Who is online
Users browsing this forum: No registered users and 1 guest