How to read and write a Domoticz variable with dzVents  [Solved]

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

Moderator: leecollings

Post Reply
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How to read and write a Domoticz variable with dzVents

Post by gschmidt »

Hi,

I am trying to create a doorbell dzVents script. (I have a working blockly version)
The doorbell device is an RFXtrx433XL device (cheap Action stuff)
When pressed (depending on the pressure) it sends in a few milliseconds a few On commands.
So a domoticz variable is used to turn on a virtual on/off switch which sends a voice command to my google homes (in node-red)

The script is not working though because can't find how to access (read and write) the domoticz variable "deurbellen"
This my current script but apparently the "variable" method I use is not correct.

-- Send Telegram Notification if Deurbel (RFXtrx433XL) is turned on
-- and also turns on a virtual on/off switch which activates a google home voice command in node-red

Code: Select all

return {
   on =
    { 
        devices = {'Deurbel'}
    },
    {
        variables = { 'deurbellen' }
    },
   
   execute = function(dz, variable)
        
        local Switch = dz.devices('Bel_Schakelaar')
        local Security = dz.devices('Deurbel Security')
        
        if dz.devices('Deurbel').state == "On" and variable.value == 'Niet aangebeld' then

            variable.set('Er wordt aangebeld')
            Switch.cancelQueuedCommands()
            Switch.switchOn()
            
            dz.notify(Switch.name,'Er wordt aangebeld!', dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM)
            dz.log('Device ' .. Switch.name .. ' state: ' .. Switch.state, dz.LOG_INFO)
            
            Switch.switchOff().afterSec(8)
            Security.switchNormal().afterSec(8)
            variable.set('Niet aangebeld').afterSec(10)
        end
     end
}
How can I read and write the value of a Domoticz variable?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to read and write a Domoticz variable with dzVents

Post by waaren »

gschmidt wrote: Saturday 23 January 2021 13:49 The script is not working though because can't find how to access (read and write) the domoticz variable "deurbellen"
How can I read and write the value of a Domoticz variable?
Can you try this ?

I commented the line

Security.switchNormal().afterSec(8)

because switchNormal() is not a dzVents method and I don't know what you want with this.

Code: Select all

return
{
   on =
   {
        devices =
        {
            'Deurbel',
        },
   },

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


   execute = function(dz, item)

        local Switch = dz.devices('Bel_Schakelaar')
        local Security = dz.devices('Deurbel Security')
        local deurState = dz.variables('Deurbellen')
        local deurbel = dz.devices('Deurbel')

        if deurbel.state == "On" and deurState.value == 'Niet aangebeld' then

            deurState.set('Er wordt aangebeld')
            Switch.cancelQueuedCommands()
            Switch.switchOn()

            dz.notify(Switch.name,'Er wordt aangebeld!', dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM)
            dz.log('Device ' .. Switch.name .. ' state: ' .. Switch.state, dz.LOG_INFO)

            Switch.switchOff().afterSec(8)
            -- Security.switchNormal().afterSec(8) -- SwitchNormal is not a dzVents command
            deurState.set('Niet aangebeld').afterSec(10)
        end
     end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to read and write a Domoticz variable with dzVents

Post by gschmidt »

waaren wrote: Saturday 23 January 2021 15:00
gschmidt wrote: Saturday 23 January 2021 13:49 The script is not working though because can't find how to access (read and write) the domoticz variable "deurbellen"
How can I read and write the value of a Domoticz variable?
Can you try this ?

I commented the line

Security.switchNormal().afterSec(8)

because switchNormal() is not a dzVents method and I don't know what you want with this.

Code: Select all

return
{
   on =
   {
        devices =
        {
            'Deurbel',
        },
   },

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


   execute = function(dz, item)

        local Switch = dz.devices('Bel_Schakelaar')
        local Security = dz.devices('Deurbel Security')
        local deurState = dz.variables('Deurbellen')
        local deurbel = dz.devices('Deurbel')

        if deurbel.state == "On" and deurState.value == 'Niet aangebeld' then

            deurState.set('Er wordt aangebeld')
            Switch.cancelQueuedCommands()
            Switch.switchOn()

            dz.notify(Switch.name,'Er wordt aangebeld!', dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM)
            dz.log('Device ' .. Switch.name .. ' state: ' .. Switch.state, dz.LOG_INFO)

            Switch.switchOff().afterSec(8)
            -- Security.switchNormal().afterSec(8) -- SwitchNormal is not a dzVents command
            deurState.set('Niet aangebeld').afterSec(10)
        end
     end
}

Thanx man! When I learned the doorbell in domoticz, 2 devices were created: doorbell device and a security device.
If the doorbell is physically pressed the doorbell device is turned on but also the security device is set to alarm.
So I want to set this alarm back to Normal To sync this device with the doorbell.

What is the command to do this then?

Hmmm...now that I mention it, maybe I could use the alarm device instead of the virtual switch to trigger the voice alarm in node-red. This would save an extra domoticz (virtual) device
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to read and write a Domoticz variable with dzVents

Post by waaren »

gschmidt wrote: Sunday 24 January 2021 9:34 When I learned the doorbell in domoticz, 2 devices were created: doorbell device and a security device.
If the doorbell is physically pressed the doorbell device is turned on but also the security device is set to alarm.
So I want to set this alarm back to Normal To sync this device with the doorbell.

What is the command to do this then?
What is the type and subtype of this device (taken from 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
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to read and write a Domoticz variable with dzVents

Post by gschmidt »

waaren wrote: Sunday 24 January 2021 10:33
gschmidt wrote: Sunday 24 January 2021 9:34 When I learned the doorbell in domoticz, 2 devices were created: doorbell device and a security device.
If the doorbell is physically pressed the doorbell device is turned on but also the security device is set to alarm.
So I want to set this alarm back to Normal To sync this device with the doorbell.

What is the command to do this then?
What is the type and subtype of this device (taken from the devices tab) ?
Type: Security
SubType: X10 Security
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to read and write a Domoticz variable with dzVents

Post by waaren »

gschmidt wrote: Sunday 24 January 2021 13:02 Type: Security
SubType: X10 Security
can you try with

Code: Select all

Security.update(0).afterSec(8)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to read and write a Domoticz variable with dzVents  [Solved]

Post by gschmidt »

waaren wrote: Sunday 24 January 2021 14:00
gschmidt wrote: Sunday 24 January 2021 13:02 Type: Security
SubType: X10 Security
can you try with

Code: Select all

Security.update(0).afterSec(8)
Working thanx!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest