Page 1 of 1

Presence and welcome light

Posted: Friday 17 January 2020 22:20
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
    }

Re: Presence and welcome light

Posted: Friday 17 January 2020 22:49
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)

Re: Presence and welcome light  [Solved]

Posted: Saturday 18 January 2020 0:49
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
}

Re: Presence and welcome light

Posted: Saturday 18 January 2020 9:21
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
    }

Re: Presence and welcome light

Posted: Saturday 18 January 2020 15:28
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).

Re: Presence and welcome light

Posted: Sunday 17 May 2020 13:10
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
    }