Part of script does not work  [Solved]

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

Moderator: leecollings

Post Reply
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Part of script does not work

Post by Havym »

Hello everyone,

I am new to using domoticz
V4.11468
Build Hash: 508cc66a1
Build Date: 2019-11-05 16:05:44
and I like it so far. I started to study the Lua scripts and dzVents.

I get the code below working half way and I get no errors.

I use a hacked tone and when the burner(Branderinfo) comes on, the floor heating pump (Kaku switch 'Vloerverwarming') also comes on.
If the burner goes out, the pump continues to run for an hour and then goes out.
This part of the script works.

Next, i tried but didn't get it to work, if the burner does not start due to summer, the pump will start running if 'Vloerverwarming' is off for 24 hours for at least 1 hour to prevent from getting stuck.

Can you tell me what I'm doing wrong?

Code: Select all

 return {
   on = {
      devices = {'ToonBranderInfo','Vloerverwarming'},
   },
   execute = function(domoticz, device)
      if domoticz.devices('ToonBranderInfo').levelName == 'CV'
      then
         domoticz.log('Brander is aan!')
         local Vloerverwarming = domoticz.devices('Vloerverwarming')
         Vloerverwarming.switchOn()
      else
         domoticz.log('Brander is uit!')
         local Vloerverwarming = domoticz.devices('Vloerverwarming')
         Vloerverwarming.switchOff().afterHour(1)
      if domoticz.devices('Vloerverwarming').state == 'Off'
      then
          domoticz.log('Vloerverwarming pompt even rond door inactiviteit')
          local Vloerverwarming = domoticz.devices('Vloerverwarming')
          Vloerverwarming.switchOn().afterHour(24).forHour(1)
        end
      end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Part of script does not work

Post by waaren »

Havym wrote: Wednesday 27 November 2019 16:57 .... Next, i tried but didn't get it to work, if the burner does not start due to summer, the pump will start running if 'Vloerverwarming' is off for 24 hours for at least 1 hour to prevent from getting stuck.
Can you check this one ?

Code: Select all

local summer = '1/5-30/9'

return 
{
    on = 
    {
        devices = { 'ToonBranderInfo'},
        timer = { 'at 03:19 on ' .. summer},
    },
   
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(domoticz, item)
        _G.logMarker =  _G.moduleLabel
       
		local Vloerverwarming = domoticz.devices('Vloerverwarming')
        
        if item.isDevice then 
            if domoticz.devices('ToonBranderInfo').levelName == 'CV' then
                domoticz.log('Brander is aan!')
                Vloerverwarming.switchOn().checkFirst()
            elseif Vloerverwarming.state == 'On' then
                domoticz.log('Brander is uit!')
                Vloerverwarming.switchOff().afterHour(1)
            end
        else -- triggered by timer 
            Vloerverwarming.switchOn()
            Vloerverwarming.switchOff().afterHour(1)
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Part of script doenst work

Post by Havym »

Thank you for your answer. I'm a newby with scripting in any language lol
I need to study your way thats for sure..
I will give it a try.
So if i understand you correctly.. the activation for the vloerverwarming in summer needs a time trigger instead of afterHour()?

What is _G.logMarker and _G.moduleLabel? Can this be found in the manual?
Do i need the checkfirst option for a kaku? Action switches dont give a responce back what state their in.

A lot of questions, i know but with dzVents script you can create more options then with blocky.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Part of script does not work

Post by waaren »

Havym wrote: Wednesday 27 November 2019 20:10 Thank you for your answer. I'm a newby with scripting in any language lol
I need to study your way thats for sure..
I will give it a try.
So if i understand you correctly.. the activation for the vloerverwarming in summer needs a time trigger instead of afterHour()?
There are many ways to do things in any script- or programming language. I think that for your requirement this is a workable solution but I am sure there will be other ways. Just pick one that suits you
What is _G.logMarker and _G.moduleLabel? Can this be found in the manual?
_G is the global Lua table. logMarker is used as prefix for dzVents log lines and moduleLabel is the name of the script. So what I do here is set the log prefix equal to the scriptname. Both these variables are used in dzVents runtime modules (<domoticz dir>/dzVents/runtime/*.lua)
Do i need the checkFirst() option for a kaku? Action switches don't give a response back what state their in.
You don't need the option but is kind of short for

Code: Select all

if device.state ~= 'Off' then device.switchOff() end 
so it prevents unnecessary signals and change of lastUpdated timestamps (not only for KlikAan KlikUit)

A lot of questions, i know but with dzVents script you can create more options then with blocky.
Sure. That's why I post a lot of examples. Maybe it will help other forum members to enjoy domoticz / dzVents even more.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Part of script does not work

Post by Havym »

Some things i understand and some things i don't.

I tried your way of scripting and it works. The vloerverwarming turns on if Brander is on and shuts off an hour after stopping brander.

The other part where the vloerverwarming runs in summer time i didn't explain very wel. Summer time was an example why i would like to run the vloerverwarming 1 hour in 24 hours. But i need it to work in (not only summer) holidays of long weekends away when brander is off too because we are not at home.
Next, i tried but didn't get it to work, if the burner does not start due to staying off or long summer, the pump will start running if 'Vloerverwarming' is off for 24 hours for at least 1 hour to prevent from getting stuck.
So if the vloerverwarming has not been turn on in 24 hours i would like to turn it on for 1 hour. Specific time is not necessary but can be useful(middle of the night). The script i put in the starttopic didn't work.

Sorry for the misunderstanding.
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Part of script does not work

Post by Havym »

Ik denk dat ik het gevonden heb.
Ooops, english. I think i found it :D

Code: Select all

return 
{
    on = 
    {
        devices = { 'ToonBranderInfo'},
    },
   
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(domoticz, item)
        _G.logMarker =  _G.moduleLabel
       
		local Vloerverwarming = domoticz.devices('Vloerverwarming')
        
        if item.isDevice then 
            if domoticz.devices('ToonBranderInfo').levelName == 'CV' then
                domoticz.log('Brander is aan!')
                Vloerverwarming.switchOn().checkFirst()
            elseif Vloerverwarming.state == 'On' then
                domoticz.log('Brander is uit!')
                Vloerverwarming.switchOff().afterHour(1)
            elseif Vloerverwarming.state == 'Off' then
                domoticz.log('Pomp moet even draaien')
                Vloerverwarming.switchOn().afterHour(24).forHour(1)
            end
        end
    end
}
This is the result in the log
Status: dzVents: Info: ------ Start internal script: Vloerverwarming test: Device: "ToonBranderInfo (Dummy)", Index: 50
Status: dzVents: Debug: Vloerverwarming test: Processing device-adapter for Vloerverwarming: Switch device adapter
Status: dzVents: Info: Vloerverwarming test: Pomp moet even draaien
Status: dzVents: Debug: Vloerverwarming test: Constructed timed-command: On
Status: dzVents: Debug: Vloerverwarming test: Constructed timed-command: On AFTER 86400 SECONDS
Status: dzVents: Debug: Vloerverwarming test: Constructed timed-command: On AFTER 86400 SECONDS FOR 3600 SECONDS
Status: dzVents: Info: Vloerverwarming test: ------ Finished Vloerverwarming test
Status: dzVents: Debug: Commands sent to Domoticz:
Status: dzVents: Debug: - Vloerverwarming = On AFTER 86400 SECONDS FOR 3600 SECONDS
Status: dzVents: Debug: =====================================================
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Part of script does not work  [Solved]

Post by waaren »

Havym wrote: Friday 29 November 2019 9:58 Ik denk dat ik het gevonden heb.
Ooops, english. I think i found it :D
This will work in normal situations but will not do it's job when domoticz gets restarted in summer. The afterHour(24) will not work after that restart and the script will only be retriggered when it gets cold.

Maybe lastUpdate can help.

Code: Select all

return 
{
    on = 
    {
        devices = { 'ToonBranderInfo'},
        timer = { 'at 03:19'},
    },
   
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(domoticz, item)
        _G.logMarker =  _G.moduleLabel
       
        local Vloerverwarming = domoticz.devices('Vloerverwarming')
        
        if item.isDevice then 
            if domoticz.devices('ToonBranderInfo').levelName == 'CV' then
                domoticz.log('Brander is aan!')
                Vloerverwarming.switchOn().checkFirst()
            elseif Vloerverwarming.state == 'On' then
                domoticz.log('Brander is uit!')
                Vloerverwarming.switchOff().afterHour(1)
            end
        elseif Vloerverwaming.lastUpdate.hoursAgo > 22  then -- true when triggered by timer and Vloerverwarming not active in last 23-24 hours 
            Vloerverwarming.switchOn()
            Vloerverwarming.switchOff().afterHour(1)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Part of script does not work

Post by Havym »

Maybe a stupid question but why is domoticz restarted in summer in my script?

I will try your script, thanks.

Edit: it gives me an error
Error: dzVents: Error: (2.5.0) error loading module 'Vloerverwarming test' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Vloerverwarming test.lua':
scripts/dzVents/generated_scripts/Vloerverwarming test.lua:28: 'then' expected near 'Vloerverwarming'
Edit: got it. Copy paste error. 'then' is missing in your script.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Part of script does not work

Post by waaren »

Havym wrote: Friday 29 November 2019 11:54 Maybe a stupid question but why is domoticz restarted in summer in my script?
Domoticz is not restarted by your script; that is not what I meant. Let me try to explain.

First thing to understand is that any scheduled actions from commands like afterXXX, forXXX and the likes are stored in memory and not in the database. So if you say to domoticz do action-A after 24 hours it will store that in memory and when the time comes it will do action-A.
But if domoticz is restarted for whatever reason (new version, system reboot, etc..), it will start without the schedule for action-A in memory.

Hope this will make it more clear for you.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Part of script does not work

Post by Havym »

Thank you so much for your explanation. I understand now. 24 hours is to far away to be stored in memory because everything can happen. This kind of action should be stored in the database so when RPi restart for whatever reason (maybe power loss) it keeps the action.

Thank you for your help, i will study the script en try to make a new script for something else. Convert a blocky to DzVents with some extra's. :D
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Part of script does not work

Post by waaren »

Havym wrote: Friday 29 November 2019 16:03 This kind of action should be stored in the database so when RPi restart for whatever reason (maybe power loss) it keeps the action.
If you need this for whatever reason and do not want a script with a time trigger then you could also set a timer on the device itself. These timers are stored in the database. I prefer script time triggers because of the possibility to use additional conditions.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest