use device name in Variable  [Solved]

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

Moderator: leecollings

Post Reply
Draakje
Posts: 140
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 4.11539
Contact:

use device name in Variable

Post by Draakje »

Hi all,

I have this dzVent script to control the (start) level of the dimmed lights

The script works as it is (when using Dimmer 1 ) but I have now 9 dimmers which I want to control all in the same way..
I could ofcourse create 9 scripts but is it possible to use the device name in calling domoticz variable?

here is my script:

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Dimmer 1',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dimmer',
    },

    execute = function(dz, item)
        local PreviousState = dz.variables('Dimmer_1').value
        if item.sValue == 'On' and dz.time.matchesRule('at 21:00-02:00') and (PreviousState) == 'Off' then
            dz.variables('Dimmer_1').set('On') 
            item.dimTo(20).silent()
        elseif item.sValue == 'On' and dz.time.matchesRule('at 11:00-20:59') and (PreviousState) == 'Off' then
            dz.variables('Dimmer_1').set('On') 
            item.dimTo(70).silent()
        elseif item.sValue == 'Off' and (PreviousState) ~= 'Off' then
            dz.variables('Dimmer_1').set('Off') 
        end
    end
}
so basically i want something like : dz.variables('devicename').value

Thanks
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch
Draakje
Posts: 140
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 4.11539
Contact:

Re: use device name in Variable  [Solved]

Post by Draakje »

Nevermind :)

I figured it out..

I needed to use this syntax: local PreviousState = dz.variables(item.name).value
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest