Failing to understand

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

Moderator: leecollings

solarboy
Posts: 345
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Failing to understand

Post by solarboy »

Isn't that what you require or is there something more complex I have misunderstood ?
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Failing to understand

Post by FredZ »

Sorry, I may not have been entirely clear.

I was assuming that for want of a better term, the script would run every 4 hours (or timer setting)
In my lay persons speak, check the overflow sensor. If active don't turn on the pump, else turn on the pump.
once pump turns off as a result of any of the sensors becoming active the script will stop and wait for the next timer cycle.
The assumption here is that the pump gets turned off and stays off until the next timer cycle.

Regards

Fred
solarboy
Posts: 345
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Failing to understand

Post by solarboy »

This version should only turn the pump on every 4 hours if conditions are met. It will turn off as soon as condition are not met.

Code: Select all

return {
	on = {
		devices = {
		    'Switch1',
		    'Switch2',
		    'Switch3',
		    'Switch4',
		    
		    },
		timer = {
		'every 4 hours',
		},
	},
	execute = function(domoticz, item)
	    
	    local dz = domoticz
	    local dzd = dz.devices
		
		local pump = dzd('Switch1')
		local overflow = dzd('Switch2')
		local headerFull = dzd('Switch3')
		local tankLow = dzd('Switch4')
		
		local chatter = item.isDevice and item.name or item.trigger
		
		dz.log('Header Tank Script triggered by '..chatter, dz.LOG_INFO)
		
		if overflow.state == 'Off' and headerFull.state == 'Off' and tankLow.state == 'Off' -- this ensures pump will only turn on if conditions are right
		    and chatter == 'every 4 hours' -- this ensure the pump only turns ON if the script was activated by the timer
		then
		    pump.switchOn()
		    domoticz.log('Pump turning On triggered by '..chatter,dz.LOG_FORCE)
	    elseif chatter ~= 'every 4 hours'
	        then
	        pump.switchOff()
	        domoticz.log('Pump turning Off triggered by '..chatter,dz.LOG_FORCE)
        end
        
        if tankLow.state == 'On'
        then
            --put your notification method here
            domoticz.log('Tank Low',dz.LOG_FORCE)
            end
		
		
		
	end
}
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Failing to understand

Post by habahabahaba »

Let me try

Code: Select all

return {
	on = {
		devices = { 
		    'Switch2',
		    'Switch3',
		    'Switch4',
		    },
		timer = {
		'every 4 hours',
		--'every 1 minutes'  -- for testing
		},
	},
	
	logging = {
        level = domoticz.LOG_INFO,
        marker = 'Filling the tank',
    },


	execute = function(domoticz, item)
	    
	    
        local pump = domoticz.devices('Switch1')  -- as it was said the Pump had to not trigger the script
	    local overflow = domoticz.devices('Switch2')
		local headerFull = domoticz.devices('Switch3')
		local tankLow = domoticz.devices('Switch4')
	    
	   
	   
        if item.isTimer then  -- here are conditions for time 
	       
            domoticz.log('Script is triggered by timer', domoticz.LOG_INFO)
            
            
            if overflow.state == 'On' then -- or Off ? set what you need
                
                pump.switchOn().checkFirst()
                domoticz.log('Pump is turned on by timer and overflow', domoticz.LOG_INFO)
                
            else
                
                domoticz.log('Pump was NOT turned on by timer because of overflow', domoticz.LOG_INFO)
                
            end
	        
        
    

        else -- here are conditions for devices
	       
            domoticz.log('Script is triggered by device '.. item.name, domoticz.LOG_INFO)
            
            pump.switchOff().checkFirst()
            
            domoticz.log('The pump was turned off the trigger device - '.. item.name, domoticz.LOG_INFO)
            
                if item.name == 'Switch4' then -- put here the name of device
                
                    domoticz.log('The Tank level is LOW. You can put here any notification or turn the pump ON', domoticz.LOG_INFO)
                
                end
            
            
            
        	       
        end


		
	end
}
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Failing to understand

Post by FredZ »

Well done. this script seems to do what I wanted.

So what I have discovered is that there seem to be many ways to accomplish the same outcome. Also as a lay person I need to be more specific about the application and the outcome I am seeking.

There are many things I wish to do within Dom, and I am going to study what has been posted here in the vein attempt to get an understanding of how this sort of programming works. And maybe write something that functions for me. Reading the docs didn't improve my ability to understand. I felt as thought the docs were pointed toward someone with some understanding of programming.

Thank you to solarboy for the fine effort he put in and for being so tolerant of my programming ineptitude. It is pleasing to see that there are people out there that are genuinely prepared to help even if what is being asked seems simple to them.

Regards

Fred
habahabahaba wrote: Saturday 25 January 2025 14:31 Let me try

Code: Select all

return {
	on = {
		devices = { 
		    'Switch2',
		    'Switch3',
		    'Switch4',
		    },
		timer = {
		'every 4 hours',
		--'every 1 minutes'  -- for testing
		},
	},
	
	logging = {
        level = domoticz.LOG_INFO,
        marker = 'Filling the tank',
    },


	execute = function(domoticz, item)
	    
	    
        local pump = domoticz.devices('Switch1')  -- as it was said the Pump had to not trigger the script
	    local overflow = domoticz.devices('Switch2')
		local headerFull = domoticz.devices('Switch3')
		local tankLow = domoticz.devices('Switch4')
	    
	   
	   
        if item.isTimer then  -- here are conditions for time 
	       
            domoticz.log('Script is triggered by timer', domoticz.LOG_INFO)
            
            
            if overflow.state == 'On' then -- or Off ? set what you need
                
                pump.switchOn().checkFirst()
                domoticz.log('Pump is turned on by timer and overflow', domoticz.LOG_INFO)
                
            else
                
                domoticz.log('Pump was NOT turned on by timer because of overflow', domoticz.LOG_INFO)
                
            end
	        
        
    

        else -- here are conditions for devices
	       
            domoticz.log('Script is triggered by device '.. item.name, domoticz.LOG_INFO)
            
            pump.switchOff().checkFirst()
            
            domoticz.log('The pump was turned off the trigger device - '.. item.name, domoticz.LOG_INFO)
            
                if item.name == 'Switch4' then -- put here the name of device
                
                    domoticz.log('The Tank level is LOW. You can put here any notification or turn the pump ON', domoticz.LOG_INFO)
                
                end
            
            
            
        	       
        end


		
	end
}
solarboy
Posts: 345
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Failing to understand

Post by solarboy »

Glad you got it sorted and thanks for tolerating MY ineptitude also.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest