Presence en Toon

Everything about external control, apps, VNC, etc goes here.

Moderators: marcelr, TheHogNL, Toonz

Post Reply
franske88
Starting Member
Starting Member
Posts: 7
Joined: Mon Mar 05, 2018 9:46 pm

Presence en Toon

Post by franske88 »

First of all a little list with hard/software:

1x rooted toon thermostat
1x raspberry pi 4b running raspbian buster and latest domoticz
1x rflink (arduino mega with 433mhz)
1x presence script to scan the mobile phones and set a switch to on/off in domoticz
1x toon script from internet to have all switches and information.

I have a dzscript what is putt together from different scripts and inputs from other website, but its still not working like a want it to be.
The idee is when both mobile phones are away toon is switched to away setting (setpoint 10) and if one or both are at home it will set to setpoint 30.
Only running between time settings and only in winter months.
The problem is it will run even after the running time(19.59-06.59) , and it will switch back to home(after 1 min if someone is home) if the option comfort (setpoint 40) or sleeping (20) is active.
Can someone help me with the correct script, below is what i have now.

Code: Select all

return {
    on = {
        -- timer riggers
		timer = {
			-- timer triggers.. if one matches with the current time then the script is executed
			domoticz.time.matchesRule ('in week -14, 43-')
			domoticz.time.matchesRule('every minute on mon,tue,thu,fri at 07:01-19:59')
			domoticz.time.matchesRule('every minute on sat,sun at 08:01-19:59')
			function(domoticz)
				-- return true or false
			end
		},
        devices = {8, 9}, -- Zet hier de IDX'en neer van jullie telefoonswitches
    },
        logging = {
        level = domoticz.LOG_INFO,
        marker = "Telefoonscript"
    },
        execute = function(domoticz, device)
        local telefoon1 = domoticz.devices(8) -- nummer invullen van telefoons net als bij On
        local telefoon2 = domoticz.devices(9) -- idem als bij telefoon1
        toon = domoticz.devices(14) -- nummer invullen van je Toon
        
        if(telefoon1.state == "Off" and telefoon2.state == "Off") then
            toon.switchSelector(10) -- aanpassen naar de juiste waarde voor Weg in de toon
            domoticz.log('Iedereen is weg, Toon wordt geschakeld naar Weg.')
        else
        if(telefoon1.state == "On" or telefoon2.state == "On") then
            toon.switchSelector(30) -- aanpassen naar de juiste waarde voor Thuis in de toon
            domoticz.log('Iemand is thuis, Toon wordt geschakeld naar Thuis.')    
        else    
            domoticz.log('Er is nog iemand thuis, Toon wordt niet geschakeld naar Weg.')
        end
    end
end
}
TerrorSource
Administrator
Administrator
Posts: 494
Joined: Thu May 04, 2017 9:28 pm

Re: Presence en Toon

Post by TerrorSource »

Hi Franske,

First of all, i would split the script in 2.
1. Presence detection
2. Setpoint change

This way you can use both scripts with different setups like alarms for example.

I've created 1 Virtual Switch per smartphone, which will toggle status when the smartphone is "home" or "away".
Based on those switches, i've created a "home/away" script which toggles 1 general "home" or "away" script
IF 1 or more smartphone is home THEN "Home" = "On"
IFELSE 0 smartphones at home THEN "Home" = "Off"

Based on that general switch, you can control the thermostat with a 2nd DzVents script.
franske88
Starting Member
Starting Member
Posts: 7
Joined: Mon Mar 05, 2018 9:46 pm

Re: Presence en Toon

Post by franske88 »

I have a script running for the presence detection, this wil switch a virtual switch to on/off so this script is only for if one of the phones is on/off than toon must switch to.
The script in first post is for controlling the action
Last edited by franske88 on Tue Feb 18, 2020 11:47 pm, edited 1 time in total.
TerrorSource
Administrator
Administrator
Posts: 494
Joined: Thu May 04, 2017 9:28 pm

Re: Presence en Toon

Post by TerrorSource »

franske88 wrote:I have a script running for the presence detection, this wil switch a virtual switch to on/off so this script is only for if one of the phones is on/off than toon must switch to.
The script you posted in the first post of this topic is not using the "general home switch".

I use this script for presence detection. Based on this, you can create a 2nd script which will trigger based on the status the "Thuis" or "Weg" switches.

Code: Select all

local PRESENCE_DEVICES = {
        'Phone1',
        'Phone2'
    }

local IEMAND_THUIS = 'Thuis'
local NIEMAND_THUIS = 'Weg'

return {
	on = {
		devices = PRESENCE_DEVICES
	},
	execute = function(domoticz, device)
		local iemand_thuis = domoticz.devices().filter( PRESENCE_DEVICES )
		    .reduce( 
		        function (acc, device) 
		            if device.state == 'On' then
		                acc = true
		            end
		            return acc
		        end, false)

		 local sw_home = domoticz.devices(IEMAND_THUIS)
		 local sw_away = domoticz.devices(NIEMAND_THUIS)
		 
		 if iemand_thuis == true then
		     if sw_home.state ~= 'On' then
		         sw_home.switchOn()
		     end
		     if sw_away.state ~= 'Off' then
		         sw_away.switchOff()
		     end
		 else
		     if sw_home.state ~= 'Off' then
		         sw_home.switchOff()
		     end
		     if sw_away.state ~= 'On' then
		         sw_away.switchOn()
		     end
		 end
	end
}
franske88
Starting Member
Starting Member
Posts: 7
Joined: Mon Mar 05, 2018 9:46 pm

Re: Presence en Toon

Post by franske88 »

Ok I understand but based on that I must make a script what will change my room thermostaat.
Or can I use my original script only with the devices changed to the main presence device.
It's sometime so hard to get the right script everyone is saying different things.
TerrorSource
Administrator
Administrator
Posts: 494
Joined: Thu May 04, 2017 9:28 pm

Re: Presence en Toon

Post by TerrorSource »

franske88 wrote:Ok I understand but based on that I must make a script what will change my room thermostaat.
Or can I use my original script only with the devices changed to the main presence device.
It's sometime so hard to get the right script everyone is saying different things.
Make sure the separate presence detection script works, or just copy mine and change Phone1 and Phone2 in "PRESENCE_DEVICES"
If that works, try creating a script that only does 1 thing at a time, if that works, build in more functionality 1 at a time. Dont use all those time triggers at the start, build them in later.

You're trying to do 2 things at the same time, doing the presence detection AND you want to do the setpoint change.
1 script, 1 thing. Easiest to work with and maintaining.

I cannot create the full script for you, only advise what's best to start with and thats splitting the scripts and do 1 thing at a time.
franske88
Starting Member
Starting Member
Posts: 7
Joined: Mon Mar 05, 2018 9:46 pm

Re: Presence en Toon

Post by franske88 »

Ok for the good order I need the following scripts running separate.
1. A presence script that's looking for ip or Bluetooth from a device if on/off it puts a virtual switch to on or off. ( This script is already running good for weeks)
2.a second presence script that only looks if the switches from the other one are on/off and put that together to one main switch called home/away.
3. A script that will look to the home/away switch and set toon to the correct state, this script I can make bigger whit time and date codes.
TerrorSource
Administrator
Administrator
Posts: 494
Joined: Thu May 04, 2017 9:28 pm

Re: Presence en Toon

Post by TerrorSource »

franske88 wrote:Ok for the good order I need the following scripts running separate.
1. A presence script that's looking for ip or Bluetooth from a device if on/off it puts a virtual switch to on or off. ( This script is already running good for weeks)
2.a second presence script that only looks if the switches from the other one are on/off and put that together to one main switch called home/away.
3. A script that will look to the home/away switch and set toon to the correct state, this script I can make bigger whit time and date codes.
That's exactly what i mean!
Make sure it works flawless in that same order.

Good luck!

Oh and maybe you can share the 3th script when you're finished so other users can use it or use it as a reference.
franske88
Starting Member
Starting Member
Posts: 7
Joined: Mon Mar 05, 2018 9:46 pm

Re: Presence en Toon

Post by franske88 »

I am going to start building the script the upcoming days and also make a manual how you can make you're own controlled system including Kaku light control and other devices.
I noticed that there is not always a good manual to build it in correct way.
They only thing is the manual or manuals are going to be in Dutch language and maybey in the future translate into English.

The main goal of this al is to control my home based on presence or time controlled actions and use cheap hardware so everybody can build it.

For now my hardware is based on a raspberry pi 4b, Arduino mega, cheap 433mhz hardware, a cheap rooted toon, some second hand Kaku device's and other main devices almost every one have.(some stuff is coming from AliExpress)

I will post my experience of the script in the next few days.
Post Reply

Return to “Toon external control”