Selector switch for Toon

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Selector switch for Toon

Post by Slinkos » Tuesday 15 March 2016 15:52

Hi all,

I found a new way for creating a Switch to control your Toon from Domoticz on the Domoticz WIki, I followed the instructions: https://www.domoticz.com/wiki/Toon

Below I added some screenshots from my switch, and this is my code:

Code: Select all

commandArray = {}
 
-- Settings: Configure as desired
 
-- Name of the switch with the temperature setpoint.
ThermostatSetPointName = 'Room Setpoint'
 
-- Temperature SetPoints. 
HomeSetPoint = '20.50'   
ComfortSetPoint = '21.00'
SleepSetPoint = '16.00'
AwaySetPoint = '12.00' 
OffSetPoint = '6.00' --optional
 
-- Name of the selector for Toon
ToonSelector = 'Toon scene'
 
-- Name of the levels in the selector
HomeLevel = 'Thuis'
ComfortLevel = 'Comfort'
SleepLevel = 'Slapen'
AwayLevel = 'Weg'
OffLevel = 'Off' --optional
 
-- Values from each level name
HomeLevelValue = '30'
ComfortLevelValue = '40'
SleepLevelValue = '20'
AwayLevelValue = '10'
OffLevelValue = '0' --optional
 
-- End of settings
 
-- Toon Thermostat SetPoint:
ThermostatSetPoint = otherdevices_svalues[ThermostatSetPointName]
 
if (ThermostatSetPoint == HomeSetPoint) then
        --print("SetPoint equals to Home");
		if (otherdevices[ToonSelector] ~= HomeLevel) then
		print("Updating '" .. ToonSelector .. "' selector to '" .. HomeLevel .. "'")
		commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..HomeLevelValue
		end
 
elseif (ThermostatSetPoint == ComfortSetPoint) then
        --print("SetPoint equals to Comfort");
		if (otherdevices[ToonSelector] ~= ComfortLevel) then
		print("Updating '" .. ToonSelector .. "' selector to '" .. ComfortLevel .. "'")
		commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..ComfortLevelValue
		end
 
elseif (ThermostatSetPoint == SleepSetPoint) then
        --print("SetPoint equals to Sleep");
		if (otherdevices[ToonSelector] ~= 'Sleep') then
		print("Updating '" .. ToonSelector .. "' selector to '" .. SleepLevel .. "'")
		commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..SleepLevelValue
		end
 
elseif (ThermostatSetPoint == AwaySetPoint) then
        --print("SetPoint equals to Away");
		if (otherdevices[ToonSelector] ~= 'Away') then
		print("Updating '" .. ToonSelector .. "' selector to '" .. AwayLevel .. "'")
		commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..AwayLevelValue
		end
 
-- Optional		
elseif (ThermostatSetPoint == OffSetPoint) then
        --print("SetPoint equals to Off");
		if (otherdevices[ToonSelector] ~= 'Off') then
		print("Updating '" .. ToonSelector .. "' selector to '" .. OffLevel .. "'")
		commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..OffLevelValue
		end
end
 
return commandArray
But, it doesn't work. The selector switch doesn't get updated. I see the following error in my log:
2016-03-15 14:50:48.827 LUA: Updating 'Toon scene' selector to 'Weg'
2016-03-15 14:50:48.828 Error: EventSystem: in Toon scenes: [string "commandArray = {} ..."]:62: attempt to concatenate field '?' (a nil value)

So it does see that the temparture is equal to "Weg" (which is correct) but the switch doesn't get updated. Anybody got an idea what I did wrong?
Attachments
ToonSwitch.PNG
ToonSwitch.PNG (133.07 KiB) Viewed 3355 times

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by Slinkos » Wednesday 16 March 2016 14:09

I found it, the switch was named Toon Scene and in the script I said Toon scene (without a capital S)

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Tuesday 29 November 2016 14:55

Is my understanding correct in that the script only 'reads' the state of the Toon programme and updates Domoticz? Is there a script that can be used to control Toon (non hacked version) in a similar way to either the Eneco Toon app or ToonOpAfstand; or is the missing API key to this?

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Tuesday 29 November 2016 16:17

The options are to set one of the 4 states or set a setpoint
Please also check https://www.domoticz.com/wiki/Toon
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Tuesday 29 November 2016 20:57

HansieNL wrote:The options are to set one of the 4 states or set a setpoint
Please also check https://www.domoticz.com/wiki/Toon
Thought that was the case. It seems that if I change programme on Toon (to 1 of the 4), it updates Domoticz; but if I change the programme from Domoticz; it always reverts back to what Toon is set to. No error in log just a single entry when I make the change:

Code: Select all

2016-11-29 19:53:12.951 User: rjblake initiated a switch command (8/Toon Scenes/Set Level)
If I make the change using Toon or ToonOpAfstand, I get the following in the log:

Code: Select all

2016-11-29 19:58:00.105 LUA: Updating 'Toon Scenes' selector to 'Comfort'
2016-11-29 19:58:00.106 EventSystem: Script event triggered: /usr/local/domoticz/var/scripts/lua/script_time_toonselector.lua
Any ideas?

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Tuesday 29 November 2016 21:23

ToonSelector = 'Toon scene' The selector switch is named 'Toon Scene' with a capital S

Same here: if I switch from Home to Away, the switch jumps back to Home. The switch is updated to Away about 1 minute later. This is normal behaviour, because Domoticz en Toon don't communicatie realtime anymore.
So give it a minute to update and see if it works.
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Wednesday 30 November 2016 2:06

HansieNL wrote:ToonSelector = 'Toon scene' The selector switch is named 'Toon Scene' with a capital S

Same here: if I switch from Home to Away, the switch jumps back to Home. The switch is updated to Away about 1 minute later. This is normal behaviour, because Domoticz en Toon don't communicatie realtime anymore.
So give it a minute to update and see if it works.
Not sure I fully understand (think this was not my script you referred to, as I haven't posted it. In my script, I have

Code: Select all

-- Name of the selector for Toon
ToonSelector = 'Toon Scenes'
The dummy device I created is called "Toon Scenes", and the deice is called "Toon Scenes"
Screen Shot 2016-11-29 at 23.33.39.png
Screen Shot 2016-11-29 at 23.33.39.png (21.73 KiB) Viewed 2999 times
Screen Shot 2016-11-29 at 23.34.04.png
Screen Shot 2016-11-29 at 23.34.04.png (13.22 KiB) Viewed 2999 times
However...in digging through this all, I noticed that my IDX for the switch was =1 instead of =8 (correct IDX)! Changed this, but still not joy

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Wednesday 30 November 2016 17:22

@HansieNL, also on the Wiki page I see the following:

This script updates the selector level, so it doesn't execute the command actions. This way when a user operates the Toon, it will not get a second command from the selector switch. And a comment in the script itself: -- Action commands wil not be executed.

Are there some other changes needed in Domoticz (e.g. do I need create and 'Event', etc.)? All I have done is:

1. Created a script (script_time_toonselector.lua, located in /volume1/@appstore/domoticz/var/scripts/lua)
2. Added virtual hardware (Toon Scenes)
3. Created a selector switch (Toon Scenes) with the selector levels and selector actions

Domoticz gets updated if I change the setting on the Toon, but Toon does not get updated if I change setting in Domoticz.
e.g. Toon is running program 'Away', and I select 'Comfort' in Domoticz, switch updates to 'Comfort', then both 'Away' and 'Comfort' show as selected and then it returns to 'Away' and remains there. The 'status log' only shows as follows, and there are no errors being shown

Code: Select all

2016-11-30 16:03:09.263 User: rjblake initiated a switch command (8/Toon Scene/Set Level)
2016-11-30 16:04:00.308 LUA: Updating 'Toon Scene' selector to 'Away'
2016-11-30 16:04:00.310 EventSystem: Script event triggered: /usr/local/domoticz/var/scripts/lua/script_time_toonselector.lua

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Wednesday 30 November 2016 19:35

As I told before my switch gives correct status after approx a minute.
Did you wait a minute?
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Wednesday 30 November 2016 19:57

HansieNL wrote:As I told before my switch gives correct status after approx a minute.
Did you wait a minute?
Yup - it also shows that in the log

- at 16:03:09.263 User: rjblake initiated a switch command (8/Toon Scene/Set Level)
- roughly 1 minutes later 16:04:00.308 LUA: Updating 'Toon Scene' selector to 'Away' - changed to exactly what it was before

Am I right in assuming all I need is the 3 items I listed (script in the /lua/ folder, virtual hardware and switch? If I change the SetPoint, it works - just these damn switches :(

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Wednesday 30 November 2016 20:43

You just need the 3 items. Double check for typos.
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Wednesday 30 November 2016 21:58

HansieNL wrote:You just need the 3 items. Double check for typos.
Will do - Gonna just copy the Wiki script and change my devices to match and go from there...:)

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Wednesday 30 November 2016 22:44

Scrap that - I'm an idiot....I see I should have been using the IDX for the SetPoint! Changed it to this and it is now working :) - many thanks for all your help and patience :)

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Wednesday 30 November 2016 23:14

rjblake wrote:Scrap that - I'm an idiot....I see I should have been using the IDX for the SetPoint! Changed it to this and it is now working :) - many thanks for all your help and patience :)
Maybe tripple check next time :D :D :D
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Thursday 01 December 2016 17:41

Indeed...I've also made some updated slides/images to hopefully explain all the elements more clearly for the next 'idiot' like me. I'll update the Wiki to try make it foolproof

User avatar
HansieNL
Posts: 386
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi
Domoticz version: Stable
Location: NL
Contact:

Re: Selector switch for Toon

Post by HansieNL » Thursday 01 December 2016 21:28

rjblake wrote:Indeed...I've also made some updated slides/images to hopefully explain all the elements more clearly for the next 'idiot' like me. I'll update the Wiki to try make it foolproof
I've changed my script. If an other setpoint than one os the 4 status is set it is set to manual.

-- script_time_toonselector.lua
-- Reads the Toon Thermostat Setpoint Temperature and updates the
-- selector in Domoticz to represent the current Active State.
-- Off scene is an option, leave it out if not needed.
-- Action commands wil not be executed.

commandArray = {}

-- Settings: Configure as desired

-- Name of the switch with the temperature setpoint.
ThermostatSetPointName = 'Thermostaatinstelling'

-- Temperature SetPoints.
ComfortSetPoint = '20.50'
HomeSetPoint = '19.00'
SleepSetPoint = '15.00'
AwaySetPoint = '12.00'

-- Name of the selector for Toon
ToonSelector = 'Thermostaat'

-- Name of the levels in the selector
ComfortLevel = 'Comfort'
HomeLevel = 'Thuis'
SleepLevel = 'Slapen'
AwayLevel = 'Weg'
ManualLevel = 'Hand'

-- Values from each level name
ComfortLevelValue = '10'
HomeLevelValue = '20'
SleepLevelValue = '30'
AwayLevelValue = '40'
ManualLevelValue = '50'

-- End of settings

-- Toon Thermostat SetPoint:
ThermostatSetPoint = otherdevices_svalues[ThermostatSetPointName]

if (ThermostatSetPoint == ComfortSetPoint) then
--print("SetPoint equals to Comfort");
if (otherdevices[ToonSelector] ~= ComfortLevel) then
print("Updating '" .. ToonSelector .. "' selector to '" .. ComfortLevel .. "'")
commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..ComfortLevelValue
end

elseif (ThermostatSetPoint == HomeSetPoint) then
--print("SetPoint equals to Home");
if (otherdevices[ToonSelector] ~= HomeLevel) then
print("Updating '" .. ToonSelector .. "' selector to '" .. HomeLevel .. "'")
commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..HomeLevelValue
end

elseif (ThermostatSetPoint == SleepSetPoint) then
--print("SetPoint equals to Sleep");
if (otherdevices[ToonSelector] ~= 'Sleep') then
print("Updating '" .. ToonSelector .. "' selector to '" .. SleepLevel .. "'")
commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..SleepLevelValue
end

elseif (ThermostatSetPoint == AwaySetPoint) then
--print("SetPoint equals to Away");
if (otherdevices[ToonSelector] ~= 'Away') then
print("Updating '" .. ToonSelector .. "' selector to '" .. AwayLevel .. "'")
commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..AwayLevelValue
end

elseif (ThermostatSetPoint ~= HomeSetPoint and ThermostatSetPoint ~= ComfortSetPoint and ThermostatSetPoint ~= SleepSetPoint and ThermostatSetPoint ~= AwaySetPoint) then
--print("SetPoint equals to Manual");
if (otherdevices[ToonSelector] ~= 'Manual') then
print("Updating '" .. ToonSelector .. "' selector to '" .. ManualLevel .. "'")
commandArray['UpdateDevice'] = otherdevices_idx[ToonSelector]..'|1|'..ManualLevelValue
end
end

return commandArray
Blah blah blah

rjblake
Posts: 149
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Selector switch for Toon

Post by rjblake » Friday 02 December 2016 10:33

Nice - I like it. Had not thought about adding a 'Manual' indicator to the switch (although I do override the thermostat on occasion). I can certainly see the benefit to this and probably worth adding to the Wiki script and instructions. One other question/curiosity comes to mind regards the script - most other scripts I have seen declare all the variables (settings) ahead of/outside of the commandarray{}. Not sure what impact this has not doing so; but will also test that and update/change if all still good.

User avatar
EdwinK
Posts: 1239
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Selector switch for Toon

Post by EdwinK » Tuesday 24 January 2017 0:36

Thanks to this script, and looking at the posts, I've got it working. At least, when I select one of the options, I see that it changes on Toon too. The only 'problem' I've got is more of a layout thing.

Image

Thanks for this great script.
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

astrapowerrr
Posts: 60
Joined: Tuesday 31 January 2017 21:34
Target OS: -
Domoticz version:
Contact:

Re: Selector switch for Toon

Post by astrapowerrr » Wednesday 08 February 2017 21:30

Hi guys,

I'm very new with my raspberry and domoticz.
Trying now to install toon into domoticz but I get stuck at the script part.

Where do I copy that to?
To a file or in terminal?
Or somewhere else?

Thanks!

Edit:
Copied the text from the wiki into a new txt file and named it script_time_toonselector.lua.

Adjusted away to weg because that's how it's called in my domoticz. And sleep to slapen etc.
I saved this file in /home/pi/domoticz/scripts/lua

Is this correct?
Because it doesn't work like I has to do...
Last edited by astrapowerrr on Thursday 09 February 2017 22:47, edited 1 time in total.

astrapowerrr
Posts: 60
Joined: Tuesday 31 January 2017 21:34
Target OS: -
Domoticz version:
Contact:

Re: Selector switch for Toon

Post by astrapowerrr » Thursday 09 February 2017 14:23

Nobody?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests