Page 1 of 1

Converting Blockly to dzvents

Posted: Thursday 29 August 2024 6:41
by ilkaskim
Good morning, I have a blockly that works well. Unfortunately when switching to dzvents it no longer works and I can't find the error either. To be honest, I'm not very good at it either :)
Screenshot 2024-08-29 063330.png
Screenshot 2024-08-29 063330.png (128.61 KiB) Viewed 1020 times

Code: Select all

return
{
   on = {
        devices = { 'Alarm-Status', 'Werkstatt Tür Status', 'Bewegungsmelder', },
        --timer = { 'at nighttime' },
   },

   logging = {
        level = domoticz.LOG_DEBUG,
        marker = 'Alarmanlage Aktviert',
   },


   execute = function(dz, item)

        local Kompressor = dz.devices('Kompressor')
        local AlarmAktivieren = dz.devices('Alarmanlage Aktivieren')
        local Licht1 = dz.devices('Licht 1')
        local AlarmStatus = dz.devices('Alarm-Status')
        local Bewegungsmelder = dz.devices('Bewegungsmelder')
        local WerkstattTur = dz.devices('Werkstatt Tür Status')
        local Alarmanlage = dz.variables('Alarmanlage')
        local LautstWerkstatt = dz.devices('Lautstärke Werkstatt')
        local AlarmArmingMode = dz.devices('Alarm - Arming Mode (Zone 0)')
        local RadioWerkstatt = dz.devices('Radio Werkstatt')
        

        if AlarmStatus.state == 'Open' then

            Alarmanlage.set('1')
            RadioWerkstatt.switchSelector(10).afterSec(5)
            AlarmArmingMode.switchSelector(0).afterSec(1)
            LautstWerkstatt.dimTo(80)
            dz.notify('Werkstatt Alarm', 'Aus', dz.PRIORITY_NORMAL, dz.SOUND_NONE,'', dz.NSS_PUSHOVER)
        
    elseif AlarmStatus.state == 'Closed' and WerkstattTur.state == 'Closed' then --and Bewegungsmelder.lastUpdate.minutesAgo > 1 then
            
            --AlarmAktivieren.switchOn()
            RadioWerkstatt.switchSelector(0).afterSec(2)
            Alarmanlage.set('0').afterSec(10)
            Kompressor.switchOff()
            Licht1.switchOff()
            AlarmArmingMode.switchSelector(20).afterSec(3)
            LautstWerkstatt.dimTo(0)
            Alarmanlage.set('0')
            dz.notify('Werkstatt Alarm', 'Ein', dz.PRIORITY_NORMAL, dz.SOUND_NONE,'', dz.NSS_PUSHOVER)

    elseif AlarmStatus.state == 'Open' and Bewegungsmelder.state == 'Open' and (dz.time.matchesRule("between sunrise or sunset")) then
            
            Licht1.switchOn().forMin(5)
            Alarmanlage.set('1')
            --AlarmStatus.set('1').afterSec(10)
            --Switch.cancelQueuedCommands()
            --Switch.switchOn()
        end
 end
}
I would be very grateful for help

Re: Converting Blockly to dzvents

Posted: Thursday 29 August 2024 11:23
by willemd
What does "no longer works" mean? Please be more specific?
Is it triggered?
Are parts working and other parts not?
Are updates not done?
Any error messages?

Please note that you have commented out some lines by using "--". Is that intentional? It makes the action different from the blockly.

Also you have used extra conditions in the if statements when compared to the blockly.

So therefore you can't expect them to work the same.

Re: Converting Blockly to dzvents

Posted: Thursday 29 August 2024 16:09
by ilkaskim
Hello, thank you for the feedback.
The problem is, Blockly works everything correctly.
With the dzVents code it works until the first part "if". "elseif" doesn't work and there is no error message.
I also modified the blockly a bit and the changes also work. With the first elseif with the addition and it no longer works.



Code: Select all

return
{
   on = {
        devices = { 'Alarm-Status' },
   },

   logging = {
        level = domoticz.LOG_DEBUG,
        marker = 'Alarmanlage Aktviert',
   },


   execute = function(dz, item)

        local Kompressor = dz.devices('Kompressor')
        local AlarmAktivieren = dz.devices('Alarmanlage Aktivieren')
        local Licht1 = dz.devices('Licht 1')
        local AlarmStatus = dz.devices('Alarm-Status')
        local Bewegungsmelder = dz.devices('Bewegungsmelder')
        local WerkstattTur = dz.devices('Werkstatt Tür Status')
        local Alarmanlage = dz.variables('Alarmanlage')
        local LautstWerkstatt = dz.devices('Lautstärke Werkstatt')
        local AlarmArmingMode = dz.devices('Alarm - Arming Mode (Zone 0)')
        local RadioWerkstatt = dz.devices('Radio Werkstatt')
        

        if AlarmStatus.state == 'Open' then

            Alarmanlage.set('1')
            RadioWerkstatt.switchSelector(10).afterSec(5)
            AlarmArmingMode.switchSelector(0).afterSec(1)
            LautstWerkstatt.dimTo(80)
            dz.notify('Werkstatt Alarm', 'Aus', dz.PRIORITY_NORMAL, dz.SOUND_NONE,'', dz.NSS_PUSHOVER)
        
    elseif AlarmStatus.state == 'Closed' and WerkstattTur.state == 'Closed' then
            
            
            RadioWerkstatt.switchSelector(0).afterSec(2)
            Alarmanlage.set('0').afterSec(10)
            Kompressor.switchOff()
            Licht1.switchOff()
            AlarmArmingMode.switchSelector(20).afterSec(10)
            LautstWerkstatt.dimTo(0)
            dz.notify('Werkstatt Alarm', 'Ein', dz.PRIORITY_NORMAL, dz.SOUND_NONE,'', dz.NSS_PUSHOVER)

    elseif AlarmStatus.state == 'Open' and Bewegungsmelder.state == 'Open' and (dz.time.matchesRule("between sunrise or sunset")) then
            
            Licht1.switchOn().forMin(5)
            Alarmanlage.set('1')

        end
 end
}

Re: Converting Blockly to dzvents

Posted: Thursday 29 August 2024 17:22
by willemd
Your statement "dz.time.matchesRule("between sunrise or sunset")" seems to be the exact opposite of what is being used in blockly.
The above is during daytime, the blockly is during nighttime.

Also in blockly, the else-if is not really an else-if like you might be used to from other programming languages in the sense that normally this "elseif" is only checked if the preceeding "if" is not true. In blockly the "elseif" is always checked, it is more a sequential if, a next-if. So in blockly the second elseif (3rd block) will be checked and executed when true. But in dzVents it will only be checked if the first "if" is not true, which makes the second "elseif" automatically not true, so it will never be executed. (It does not explain why the first "elseif" is not executed though)

For debugging it is best to add a number of dz.log() statements to your code so you can see what the value is of the status devices that you are testing and so you can see which part of the code is executed.

Re: Converting Blockly to dzvents

Posted: Thursday 29 August 2024 17:24
by Kedi
Try changing

Code: Select all

"between sunrise or sunset"
in

Code: Select all

"between sunrise and sunset"
But I wonder if such a rule might be present.
Otherwise change it to

Code: Select all

dz.time.isDayTime
or
dz.time.isNightTime
depending what you want.
@willemd beat me to it.

Re: Converting Blockly to dzvents

Posted: Friday 30 August 2024 12:08
by FlyingDomotic
Kedi wrote: Thursday 29 August 2024 17:24 Try changing

Code: Select all

"between sunrise or sunset"
in

Code: Select all

"between sunrise and sunset"
But I wonder if such a rule might be present.
Yes, it is!

Here are examples from Domoticz documentation, giving an idea of what you can ask to "on=timer=" or "time.matchesRule":

Code: Select all

'every minute',             -- causes the script to be called every minute
'every other minute',       -- minutes: xx:00, xx:02, xx:04, ..., xx:58
'every <xx> minutes',       -- starting from xx:00 triggers every xx minutes (0 > xx < 60)
'every hour',               -- 00:00, 01:00, ..., 23:00 (24x per 24hrs)
'every other hour',         -- 00:00, 02:00, ..., 22:00 (12x per 24hrs)
'every <xx> hours',         -- starting from 00:00, triggers every xx hours (0 > xx < 24)
'at 13:45',                 -- specific time
'at *:45',                  -- every 45th minute in the hour
'at 15:*',                  -- every minute between 15:00 and 16:00
'at 12:45-21:15',           -- between 12:45 and 21:15. You cannot use '*'!
'at 19:30-08:20',           -- between 19:30 and 8:20 (next day)
'at 13:45 on mon,tue',      -- at 13:45 only on Mondays and Tuesdays (english)
'on mon,tue',               -- on Mondays and Tuesdays
'every hour on Saturday',   -- you guessed it correctly
'at sunset',                -- uses sunset/sunrise/solarnoon info from Domoticz
'at sunrise',
'at <astroMoment>',         -- dzVents >= 3.0.16 Uses the times received from Domoticz
'at <astroMoment> on sat,sun',
'xx minutes before <astroMoment>',  --
'xx minutes after <astroMoment>',   -- Please note that these relative times will cross dates
'between aa and bb'         -- aa/bb can be a time stamp like 15:44 (if aa > bb will cross dates),  aa/bb can be sunrise/sunset/solarnoon ('between sunset and sunrise' and 'between solarnoon and sunrise' will cross dates), aa/bb can be 'xx minutes before/after <astroMoment>'
'at <astroRange>',          -- between <astroMoment>start and <astroMoment>end
'at nighttime',             -- between sunset and sunrise
'at daytime',               -- between sunrise and sunset
'at daytime on mon,tue',    -- between sunrise and sunset only on Mondays and Tuesdays
'in week 1-7,44'            -- in week 1-7 or 44
'in week 20-25,33-47'       -- between week 20 and 25 or week 33 and 47
'in week -12, 33-'          -- week <= 12 or week >= 33
'every odd week',
'every even week',          -- odd or even numbered weeks
'on 23/11',                 -- on 23rd of November (dd/mm)
'on 23/11-25/12',           -- between 23/11 and 25/12
'on 2/3-8/3,7/8,6/10-14/10',-- between march 2 and 8, on august 7 and between October 6 and 14.
'on */2,15/*',              -- every day in February or every 15th day of the month
'on -3/4,4/7-',             -- before 3/4 or after 4/7
'at 12:45-21:15 except at 18:00-18:30', -- between 12:45 and 21:15 but not between 18:00 and 18:30 ( except supported from 3.0.16 onwards )
'at daytime except on sun',             -- between sunrise and sunset but not on Sundays
'at daytime or at 23:12',               -- between sunrise and sunset and also at 23:12

Re: Converting Blockly to dzvents  [Solved]

Posted: Friday 30 August 2024 13:52
by solarboy
I actually used chat gpt for this by "exporting" the Blockly code and pasting into chatgpt. Obviously the code needs cleaning up after but it worked for me.

Re: Converting Blockly to dzvents

Posted: Friday 30 August 2024 16:41
by ilkaskim
thank you very much for the answers. I'll take a closer look at how I can best implement it. I also like the idea of ​​ChatGPT.