Page 1 of 1

How to read and write a Domoticz variable with dzVents

Posted: Saturday 23 January 2021 13:49
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?

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

Posted: Saturday 23 January 2021 15:00
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
}


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

Posted: Sunday 24 January 2021 9:34
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

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

Posted: Sunday 24 January 2021 10:33
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) ?

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

Posted: Sunday 24 January 2021 13:02
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

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

Posted: Sunday 24 January 2021 14:00
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)

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

Posted: Monday 25 January 2021 18:57
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!