Presence and welcome light  [Solved]

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

Moderator: leecollings

Post Reply
Wous
Posts: 4
Joined: Friday 05 January 2018 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Presence and welcome light

Post by Wous »

Although DzVents seems to be powerful, I have to say that I've had more succes with other languages. Nevertheless I want to manage this language finally. Can someone help me with the next code?
I want to convert my mobile phone switches to the amount of people who are at home. At night, I want to trigger the arrival a light to switch on.
Next code gives a log that says who's arriving / leaving. No other logs are given and the User Variable isn't updated. What's wrong?

Code: Select all

return {
	on = {
		devices = {
			'Wouter',
			'Marieke'
		}
	},

	logging = {
    level = domoticz.LOG_DEBUG,
    marker = "iemandThuis - "
    },

	execute = function(domoticz, device, triggerInfo)
	    local iemandThuis = domoticz.variables('iemandThuis')
	    local lamp = domoticz.devices('Banklamp')
	    domoticz.log('Nu is de bezetting: ', iemandThuis.value)
	    --local lamp = domoticz.devices('Keukentafellamp')
	    
	    if device.active then
		    domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
		    if iemandThuis.value == 0 then
		        domoticz.log('nu moet de uservariable 1 worden')
	            iemandThuis.set(1)
	            if domoticz.time.isNightTime then
			        lamp.switchOn().forMin(20)
			        --lamp.dimLevel(60)
			        domoticz.log(device.name .. ' is alleen thuis, daarom keukentafellamp aangezet voor 20 minuten')
		        end
	        elseif iemandThuis.value == 1 then
	            iemandThuis.set(2)
		    end
	    else domoticz.log(device.name .. ' is vertrokken', domoticz.LOG_INFO)
	        if iemandThuis == 2 then
	            domoticz.variables('iemandThuis').set(1)
	        elseif iemandThuis == 1 then
	            domoticz.variables('iemandThuis').set(0)
		    end
		end
	end
    }
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Presence and welcome light

Post by boum »

Code looks good.
I can only think to check the value and the type of the variable is integer, just add the log line:

Code: Select all

	    domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
	    domoticz.log('iemandThuis is ' .. iemandThuis.type .. ' and value ' .. iemandThuis.value, domoticz.LOG_INFO)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Presence and welcome light  [Solved]

Post by waaren »

Wous wrote: Friday 17 January 2020 22:20 Can someone help me with the next code?
I want to convert my mobile phone switches to the amount of people who are at home. At night, I want to trigger the arrival a light to switch on.
Next code gives a log that says who's arriving / leaving. No other logs are given and the User Variable isn't updated. What's wrong?

Code: Select all

	    domoticz.log('Nu is de bezetting: ', iemandThuis.value)
The above line is incorrect. it should be

Code: Select all

domoticz.log('Nu is de bezetting: '  ..  iemandThuis.value, domoticz.LOG_INFO)
Can you try this ? If not working as expected please include the log.

Code: Select all

return 
{
    on = {
        devices = {
            'Wouter',
            'Marieke'
        }
    },

    logging = 
    {
                    level = domoticz.LOG_DEBUG,
                    marker = "iemandThuis - "
    },

    execute = function(domoticz, device, triggerInfo)
        local iemandThuis = domoticz.variables('iemandThuis')
        local lamp = domoticz.devices('Banklamp')
        local WouterThuis = domoticz.devices('Wouter').active and 1 or 0
        local MariekeThuis = domoticz.devices('Marieke').active and 1 or 0
        local inHouseBefore = iemandThuis.value
        local peopleAtHome = WouterThuis + MariekeThuis
        --local lamp = domoticz.devices('Keukentafellamp')
        
        domoticz.log('Nu is de bezetting: ' .. iemandThuis.value,domoticz.LOG_INFO)
        
        if device.active then
            domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
            if inHouseBefore < 1  and domoticz.time.isNightTime then
                lamp.switchOn().forMin(20)
                --lamp.dimLevel(60)
                domoticz.log(device.name .. ' is alleen thuis, daarom keukentafellamp aangezet voor 20 minuten',domoticz.LOG_INFO )
            end
        else 
            domoticz.log(device.name .. ' is vertrokken', domoticz.LOG_INFO)
        end
        if inHouseBefore ~= peopleAtHome  then iemandThuis.set(peopleAtHome) end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wous
Posts: 4
Joined: Friday 05 January 2018 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Presence and welcome light

Post by Wous »

That's it! domoticz.LOG_INFO is needed apparently.. Works as I wanted..

Code: Select all

return {
    -- Count the attendees, based on the mobile phones (look for Check_presence)
    -- On arrival after sunset light is switched on for x minutes.
	on = {
		devices = {
			'switch 1',
			'switch 2'
		}
	},

	logging = {
    level = domoticz.LOG_INFO,
    marker = "iemandThuis - "
    },

	execute = function(domoticz, device, triggerInfo)
	    local iemandThuis = domoticz.variables('iemandThuis')
	    --local lamp = domoticz.devices('Banklamp')
	    local lamp = domoticz.devices('Keukentafellamp')
	    
	    if device.active then
		    domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
		    if iemandThuis.value == 0 then
		        domoticz.log('nu moet de uservariable 1 worden')
	            iemandThuis.set(1)
	            if domoticz.time.isNightTime then
			        lamp.switchOn().forMin(20)
			        lamp.dimLevel(60)
			        domoticz.log(device.name .. ' is alleen thuis, daarom keukentafellamp aangezet voor 20 minuten', domoticz.LOG_INFO)
		        end
	        elseif iemandThuis.value == 1 then
	            iemandThuis.set(2)
		    end
	    else domoticz.log(device.name .. ' is vertrokken', domoticz.LOG_INFO)
	        if iemandThuis == 2 then
	            domoticz.variables('iemandThuis').set(1)
	        elseif iemandThuis == 1 then
	            domoticz.variables('iemandThuis').set(0)
		    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: Presence and welcome light

Post by waaren »

Wous wrote: Saturday 18 January 2020 9:21 That's it! domoticz.LOG_INFO is needed apparently.. Works as I wanted..
That was not the real issue.
In your code you misplaced
iemandThuis.value
in such a way that it was interpreted as the second parameter of the domoticz.log function (the loglevel) where it supposed to be part of the first parameter (the string to display).
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Presence and welcome light

Post by Larsoss »

Wous wrote: Friday 17 January 2020 22:20 Although DzVents seems to be powerful, I have to say that I've had more succes with other languages. Nevertheless I want to manage this language finally. Can someone help me with the next code?
I want to convert my mobile phone switches to the amount of people who are at home. At night, I want to trigger the arrival a light to switch on.
Next code gives a log that says who's arriving / leaving. No other logs are given and the User Variable isn't updated. What's wrong?

Code: Select all

return {
	on = {
		devices = {
			'Wouter',
			'Marieke'
		}
	},

	logging = {
    level = domoticz.LOG_DEBUG,
    marker = "iemandThuis - "
    },

	execute = function(domoticz, device, triggerInfo)
	    local iemandThuis = domoticz.variables('iemandThuis')
	    local lamp = domoticz.devices('Banklamp')
	    domoticz.log('Nu is de bezetting: ', iemandThuis.value)
	    --local lamp = domoticz.devices('Keukentafellamp')
	    
	    if device.active then
		    domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
		    if iemandThuis.value == 0 then
		        domoticz.log('nu moet de uservariable 1 worden')
	            iemandThuis.set(1)
	            if domoticz.time.isNightTime then
			        lamp.switchOn().forMin(20)
			        --lamp.dimLevel(60)
			        domoticz.log(device.name .. ' is alleen thuis, daarom keukentafellamp aangezet voor 20 minuten')
		        end
	        elseif iemandThuis.value == 1 then
	            iemandThuis.set(2)
		    end
	    else domoticz.log(device.name .. ' is vertrokken', domoticz.LOG_INFO)
	        if iemandThuis == 2 then
	            domoticz.variables('iemandThuis').set(1)
	        elseif iemandThuis == 1 then
	            domoticz.variables('iemandThuis').set(0)
		    end
		end
	end
    }
So if I want to use your script what value should I change? I use Idetect, and have the values ​​"Is iemand thuis."

My lamp is called ''Woonkamerlamp''
And your Device is your phone I assume? So in my situation Lars Iphone
So like this?

Code: Select all

return {
    -- Count the attendees, based on the mobile phones (look for Check_presence)
    -- On arrival after sunset light is switched on for x minutes.
	on = {
		devices = {
			'Lars Iphone',
			'Desiree Huawei'
		}
	},

	logging = {
    level = domoticz.LOG_INFO,
    marker = "iemandThuis - "
    },

	execute = function(domoticz, device, triggerInfo)
	    local iemandThuis = domoticz.variables('Is iemand thuis.')
	    --local lamp = domoticz.devices('Banklamp')
	    local lamp = domoticz.devices('Woonkamerlamp')
	    
	    if device.active then
		    domoticz.log(device.name .. ' is thuis gekomen', domoticz.LOG_INFO)
		    if iemandThuis.value == 0 then
		        domoticz.log('nu moet de uservariable 1 worden')
	            iemandThuis.set(1)
	            if domoticz.time.isNightTime then
			        lamp.switchOn().forMin(20)
			        lamp.dimLevel(60)
			        domoticz.log(device.name .. ' is alleen thuis, daarom keukentafellamp aangezet voor 20 minuten', domoticz.LOG_INFO)
		        end
	        elseif iemandThuis.value == 1 then
	            iemandThuis.set(2)
		    end
	    else domoticz.log(device.name .. ' is vertrokken', domoticz.LOG_INFO)
	        if iemandThuis == 2 then
	            domoticz.variables('iemandThuis').set(1)
	        elseif iemandThuis == 1 then
	            domoticz.variables('iemandThuis').set(0)
		    end
		end
	end
    }
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
Post Reply

Who is online

Users browsing this forum: renerene and 1 guest