Controlling Toon [HACKED] from Domoticz

For heating/cooling related questions in Domoticz

Moderator: leecollings

manyakim
Posts: 4
Joined: Sunday 26 June 2016 14:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by manyakim »

Hello, i've tried all the above, but still getting the following error message :

2017-03-09 18:46:00.470 Error: EventSystem: in Toon iets: [string "-- Time script runs every minute, intended to..."]:26: attempt to index global 'jsonThermostatInfo' (a nil value)

Did someone was able to adress what's causing this error messages ?

Thanks
balans
Posts: 7
Joined: Tuesday 05 July 2016 9:32
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by balans »

I`m also having the same error`s running on a linux system.
applying changes from Domotics arrive on the Toon.
But the info/changes from Toon to Domoticz don`t.
I guess there might be the problem but i dont have any lua knowledge to fix it
I followed the guidings in this topic.
So i guess i might be missing something
Timeless
Posts: 41
Joined: Friday 10 June 2016 23:46
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by Timeless »

I've added several improvements.

- Check each value for a nil value (in case of a failed request)
- Changed all global allocations to local. This is to prevent a memory leak. (This is how LUA works)
- Added a timeout to curl (--max-time) which will prevent the script from running for more than 10 seconds and thus decreasing the warnings, in case Toon can't be reached. Please take note that this will also ignore the values for that particular request.

Please change the line "local json = assert(loadfile "/opt/domoticz/scripts/lua/JSON.lua")()" accordingly

If this script fails, please check if the url "http://127.0.0.1/happ_thermstat?action=getThermostatInfo"(change IP/hostname) can be reached from another device, and returns valid JSON.

Code: Select all

-- Time script runs every minute, intended to sync Domoticz with Toon in case the value is changed on the physical device.
-- Updates Toon Thermostat Sensor to value set on Toon
-- Updates Toon Temperature Sensor to value set on Toon
-- Updates Toon Scenes switch based on program set on Toon
-- Updates Toon Auto Program switch to value set on Toon
-- Updates Toon program information text to value set on Toon

commandArray = {}

    local ToonThermostatSensorName = uservariables['UV_ToonThermostatSensorName'] -- Sensor showing current setpoint
    local ToonTemperatureSensorName = uservariables['UV_ToonTemperatureSensorName'] -- Sensor showing current room temperature
    local ToonScenesSensorName  = uservariables['UV_ToonScenesSensorName'] -- Sensor showing current program
    local ToonAutoProgramSensorName = uservariables['UV_ToonAutoProgramSensorName'] -- Sensor showing current auto program status
    local ToonProgramInformationSensorName = uservariables['UV_ToonProgramInformationSensorName'] -- Sensor showing displaying program information status
    local ToonIP = uservariables['UV_ToonIP']
    local DomoticzIP = uservariables['UV_DomoticzIP']
    local ToonProgramInformationSensorValue;

    local json = assert(loadfile "/opt/domoticz/scripts/lua/JSON.lua")()  -- For Linux (LEDE)
   
    local handle = assert(io.popen(string.format('curl -m 5 http://%s/happ_thermstat?action=getThermostatInfo', ToonIP)))
        local ThermostatInfo = handle:read('*all')
    handle:close()
   
    local jsonThermostatInfo = json:decode(ThermostatInfo)
   
    if jsonThermostatInfo ~= nil then
        local currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100
        local currentTemperature = tonumber(jsonThermostatInfo.currentTemp) / 100
        local currentProgramState = tonumber(jsonThermostatInfo.programState)
        local currentActiveState = tonumber(jsonThermostatInfo.activeState)
        local currentNextTime = jsonThermostatInfo.nextTime
        local currentNextSetPoint = tonumber(jsonThermostatInfo.nextSetpoint) / 100
   
        if currentSetpoint ~= nil then 
            -- Update the thermostat sensor to current setpoint
            if otherdevices_svalues[ToonThermostatSensorName]*100 ~= currentSetpoint*100 then 
                print('Updating thermostat sensor to new set point: ' ..currentSetpoint)
                commandArray[1] = {['Variable:UV_ToonChangedByDomoticz'] = '1'} -- Set variable changed to 1 to prevent script ToonSetPoint from shooting an event at Toon
                commandArray[2] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonThermostatSensorName], currentSetpoint)}
            end
        end
   
        if currentTemperature ~= nil then 
            -- Update the temperature sensor to current room temperature
            if otherdevices_svalues[ToonTemperatureSensorName]*100 ~= currentTemperature*100 then
                print('Updating the temperature sensor to new value: ' ..currentTemperature)
                commandArray[3] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonTemperatureSensorName], currentTemperature)}
            end
        end
   
        if currentActiveState ~= nil then 
            -- Update the toon scene selector sensor to current program state
            local CurrentToonScenesSensorValue = otherdevices_svalues[ToonScenesSensorName]
   
            if currentActiveState == -1 then currentActiveState = '50' -- Manual
            elseif currentActiveState == 0 then currentActiveState = '40' -- Comfort
            elseif currentActiveState == 1 then currentActiveState = '30' -- Home
            elseif currentActiveState == 2 then currentActiveState = '20' -- Sleep
            elseif currentActiveState == 3 then currentActiveState = '10' -- Away
            end
    
            if CurrentToonScenesSensorValue ~= currentActiveState then  -- Update toon selector if it has changed
                print ('Updating Toon Scenes selector')
                commandArray[4] = {['UpdateDevice'] = string.format('%s|1|%s', otherdevices_idx[ToonScenesSensorName], currentActiveState)}
            end
        end
   
        if currentProgramState ~= nil then 
            -- Updates the toon auto program switch
            local CurrentToonAutoProgramSensorValue = otherdevices_svalues[ToonAutoProgramSensorName]
   
           if currentProgramState == 0 then currentProgramState = '10' -- No
            elseif currentProgramState == 1 then currentProgramState = '20' -- Yes
            elseif currentProgramState == 2 then currentProgramState = '30' -- Temporary       
            end
   
            if CurrentToonAutoProgramSensorValue ~= currentProgramState then -- Update toon auto program selector if it has changed
                print ('Updating Toon Auto Program selector')
                commandArray[5] = {['UpdateDevice'] = string.format('%s|1|%s', otherdevices_idx[ToonAutoProgramSensorName], currentProgramState)}
            end
        end
   
        if currentNextTime ~= nil and currentNextSetPoint ~= nil then 
            -- Updates the toon program information text box
            local CurrentToomProgramInformationSensorValue = otherdevices_svalues[ToonProgramInformationSensorName]
            if currentNextTime == 0 or currentNextSetPoint == 0 then
                ToonProgramInformationSensorValue = 'Op ' ..currentSetpoint.. '°'
            else
                ToonProgramInformationSensorValue = 'Om ' ..os.date('%H:%M', currentNextTime).. ' op ' ..currentNextSetPoint.. '°'
            end
   
            if CurrentToomProgramInformationSensorValue ~= ToonProgramInformationSensorValue then
                commandArray[6] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonProgramInformationSensorName], ToonProgramInformationSensorValue)}
            end
        end
    end
--
return commandArray
"The greatest good you can do for another, is not to share your own riches, but to reveal to him, his own."
- Benjamin Disraeli -
balans
Posts: 7
Joined: Tuesday 05 July 2016 9:32
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by balans »

Hi sorry for the late reply

when i reach for toon i get a

Code: Select all

{"result":"ok", "currentTemp":"2058", "currentSetpoint":"1800", "currentInternalBoilerSetpoint":"6", "programState":"1", "activeState":"3", "nextProgram":"1", "nextState":"0", "nextTime":"1491490800","nextSetpoint":"2000","randomConfigId":"1681692777","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"0"}
but when running youre new script and the modded folder i still and up with the same

Code: Select all

2017-04-06 13:49:00.998 Error: EventSystem: in toonsync: [string "-- Time script runs every minute, intended to..."]:37: attempt to perform arithmetic on field '?' (a nil value)
QuasaR
Posts: 4
Joined: Tuesday 15 July 2014 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by QuasaR »

I am also having issue's with the new script.

Code: Select all

2017-04-06 15:10:04.966  Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_synctoon.lua: /home/pi/domoticz/scripts/lua/JSON.lua:1009: /home/pi/domoticz/scripts/lua/JSON.lua:660: expected string's opening quote at char 353 of: {"result":"ok", "currentTemp":"2170", "currentSetpoint":"2100", "currentInternalBoilerSetpoint":"6", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1491503400","nextSetpoint":"2200","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"0",}
2017-04-06 15:11:00.313  Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_synctoon.lua: /home/pi/domoticz/scripts/lua/JSON.lua:1009: /home/pi/domoticz/scripts/lua/JSON.lua:660: expected string's opening quote at char 353 of: {"result":"ok", "currentTemp":"2170", "currentSetpoint":"2100", "currentInternalBoilerSetpoint":"6", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1491503400","nextSetpoint":"2200","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"0",}
2017-04-06 15:12:03.634  Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_synctoon.lua: /home/pi/domoticz/scripts/lua/JSON.lua:1009: /home/pi/domoticz/scripts/lua/JSON.lua:660: expected string's opening quote at char 353 of: {"result":"ok", "currentTemp":"2170", "currentSetpoint":"2100", "currentInternalBoilerSetpoint":"6", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1491503400","nextSetpoint":"2200","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"0",}
I think it has todo with the , at the end of the line before the }.
balans
Posts: 7
Joined: Tuesday 05 July 2016 9:32
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by balans »

I sorted my problems i had made i typo :oops: temparature instead of temperature in the events list :oops: that was al the cullprit..
running great now. Thank everybody involved for the scripts and modifications on the scripts :!:
now start looking for al solution to read the allready logged power gas from domoticz in the toon. So i`m up for a hint :lol:
terrorsource
Posts: 67
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by terrorsource »

I want to control my Toon from Domoticz, which is being controlled by HomeBridge (So i can use Siri to set the temperature).
Already have the LUA code in place. it's reading the environment temperature correctly but Domoticz won't update the temperature in Toon when i change it.

Code: Select all

-- Script used for Toon Thermostaat utility device, upon changing temp in Domoticz, temperature is sent to Toon. 
commandArray = {}

    ToonThermostatSensorName = uservariables['UV_ToonThermostatSensorName'] -- Sensor showing current setpoint
    ToonIP = uservariables['UV_ToonIP']
    
    for deviceName,deviceValue in pairs(devicechanged) do
        if (deviceName == ToonThermostatSensorName) then
            if uservariables['UV_ToonChangedByDomoticz'] == 1 then
                commandArray['Variable:UV_ToonChangedByDomoticz'] = '0'
            else
                SetPoint = otherdevices_svalues[ToonThermostatSensorName]
                
                print('Setting Toon setpoint to '.. SetPoint)
                commandArray['OpenURL'] = string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', ToonIP, SetPoint*100)
            end
        end
    end

return commandArray
Is working, but gives an error in logs:
Error: EventSystem: in ToonThermostat: [string "-- Script used for Toon Thermostaat utility d..."]:8: bad argument #1 to 'pairs' (table expected, got nil)
Shortend version of 1 of the previous scripts:

Code: Select all

commandArray = {}

    ToonThermostatSensorName = uservariables['UV_ToonThermostatSensorName'] -- Sensor showing current setpoint
	ToonIP = uservariables['UV_ToonIP']

    json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Raspberry
    
    local handle = assert(io.popen(string.format('curl http://%s/happ_thermstat?action=getThermostatInfo', ToonIP)))
        local ThermostatInfo = handle:read('*all')
    handle:close()
    
    jsonThermostatInfo = json:decode(ThermostatInfo)
    
    currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100
        
    -- Update the thermostat sensor to current setpoint
    if otherdevices_svalues[ToonThermostatSensorName]*100 ~= currentSetpoint*100 then  
        print('Updating thermostat sensor to new set point: ' ..currentSetpoint)
        commandArray[1] = {['Variable:UV_ToonChangedByDomoticz'] = '1'} -- Set variable changed to 1 to prevent script ToonSetPoint from shooting an event at Toon
        commandArray[2] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonThermostatSensorName], currentSetpoint)}
    end

return commandArray
Does not work, error in logs:
Error: EventSystem: Warning!, lua script ToonThermostat has been running for more than 10 seconds
We need some way to combine those 2 so we get 1 script without errors.
odelay
Posts: 4
Joined: Monday 08 December 2014 17:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by odelay »

I got a rooted Toon and followed the procedure to control it with domoticz. Everything seems to work ok exept I can't set the Toon Thermostat from domoticz. The same as terrorsource mentioned.

I also got this error message every minute:
error: EventSystem: in toon: [string "-- Script used for Toon Thermostaat utility d..."]:8: bad argument #1 to 'pairs' (table expected, got nil)

Anyone know how to fix this?

thanks!
terrorsource
Posts: 67
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by terrorsource »

odelay wrote:I got a rooted Toon and followed the procedure to control it with domoticz. Everything seems to work ok exept I can't set the Toon Thermostat from domoticz. The same as terrorsource mentioned.

I also got this error message every minute:
error: EventSystem: in toon: [string "-- Script used for Toon Thermostaat utility d..."]:8: bad argument #1 to 'pairs' (table expected, got nil)

Anyone know how to fix this?

thanks!
Well, i'm able to set the temperature with both scripts. still having the error in the logs tho.
odelay
Posts: 4
Joined: Monday 08 December 2014 17:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by odelay »

Did you changed anything since? because you wrote:

"it's reading the environment temperature correctly but Domoticz won't update the temperature in Toon when i change it."

That is exactly what I experience at the moment.
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by EdwinK »

Looks interesting to do, even if it was only to control the Toon from Domoticz, something that isn't possible anymore. But... I just don't dare.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
marcelr
Posts: 42
Joined: Friday 22 May 2015 21:10
Target OS: Linux
Domoticz version: svn 2470
Location: Ehv, NL
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by marcelr »

EdKo66 wrote:Looks interesting to do, even if it was only to control the Toon from Domoticz, something that isn't possible anymore. But... I just don't dare.
There are plenty people around at the domoticaforum.eu forum to help you out.
DennisD
Posts: 51
Joined: Friday 18 September 2015 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by DennisD »

Sorry, didn't want to open a new topic for this hacked toon question I got. I want to have my gas usage displayed in domoticz did anybody accomplished this? Can't seem to find it.
BlackysBoss
Posts: 2
Joined: Wednesday 12 July 2017 20:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by BlackysBoss »

terrorsource wrote:Does not work, error in logs:
Error: EventSystem: Warning!, lua script ToonThermostat has been running for more than 10 seconds
We need some way to combine those 2 so we get 1 script without errors.
The scripts in the first post works perfectly (After discovering a few typo's and deleting an unused variable).
The '10 seconds' problem seems to be caused by Domoticz itself: viewtopic.php?t=12579

Oh, and I'm trying to get rid of the 'Manual' and 'Temporary' setting. I get how it works, but Toon doesn't show this, so what do I need it for in Domoticz?
Timeless
Posts: 41
Joined: Friday 10 June 2016 23:46
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by Timeless »

Oh, and I'm trying to get rid of the 'Manual' and 'Temporary' setting. I get how it works, but Toon doesn't show this, so what do I need it for in Domoticz?
Correct me if I'm wrong but these states are used by toon? when the schedule is running and the temperature is manually set on Toon itself it will change it state to manual for example. Same applies to Temporary but then just for a limited time without schedule running.
Sorry, didn't want to open a new topic for this hacked toon question I got. I want to have my gas usage displayed in domoticz did anybody accomplished this? Can't seem to find it.
I've seen some functions indicating JSON output about gas and electric usage when I was browsing in Toon. But since I don't use those features (missing the Zwave sensor adaptor) I cannot verify if they work.

try:

Code: Select all

http://127.0.0.1/hdrv_zwave?action=getDevices.json 
with 127.0.0.1 replaced by your Toon IP and see if this gives some valid output.
"The greatest good you can do for another, is not to share your own riches, but to reveal to him, his own."
- Benjamin Disraeli -
DennisD
Posts: 51
Joined: Friday 18 September 2015 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by DennisD »

Already figured out the gas usage, forgot to post it here :)

For the other values you want to pull from your toon, read this post (bit old, but files still function): https://www.domoticaforum.eu/viewtopic. ... oot#p77453 . I will attach all files to this post just to share!

For the gas_data_json file (modified electricity_data_json file):

Goto http://ip_toon/hdrv_zwave?action=getDevices.json and look for:

Code: Select all

"dev_3.1":{"uuid":"eneco-001-018946:hdrv_zwave_68927F8D936", "name":"HAE_METER_v2_1", "internalAddress":"3.1", "type":"gas", "supportsCrc":"0", "CurrentGasFlow":"0.00", "CurrentGasQuantity":"3080.00", "location":"(null)"},
. The most important bit is the dev_3.1 part because that can be different in other toons. Open gas_date_json.php and search for:

Code: Select all

$gasUsage= $parsed_json['dev_3.1']['CurrentGasQuantity']; 
now change the dev_3.1 to the one you have in the mentioned url. Make sure you change the ip_toon to the ip your toon has and also make a gasmeter (add virtual sensor) and fill in the idx. If you upload to mindergas you could also add your gas meter value to the following line:

Code: Select all

 $gasUsage= $parsed_json['dev_3.1']['CurrentGasQuantity'] + yourmetervalue;
Now domoticz will have the actual meter value and you can upload it to mindergas.
Attachments
hackedtoondomoticz.rar
(3.98 KiB) Downloaded 225 times
JeDr
Posts: 1
Joined: Thursday 20 August 2015 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by JeDr »

QuasaR wrote:I am also having issue's with the new script.

Code: Select all

2017-04-06 15:10:04.966  Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_synctoon.lua: /home/pi/domoticz/scripts/lua/JSON.lua:1009: /home/pi/domoticz/scripts/lua/JSON.lua:660: expected string's opening quote at char 353 of: {"result":"ok", "currentTemp":"2170", "currentSetpoint":"2100", "currentInternalBoilerSetpoint":"6", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1491503400","nextSetpoint":"2200","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"0",}
I think it has todo with the , at the end of the line before the }.
Add the following to your script_time_synctoon.lua file below the "handle:close()" part at about rule 23:
ThermostatInfo = ThermostatInfo:gsub("%,}", "}")

This should be something like:

Code: Select all

local handle = assert(io.popen(string.format('curl http://%s/happ_thermstat?action=getThermostatInfo', ToonIP)))
     local ThermostatInfo = handle:read('*all')
handle:close()

ThermostatInfo = ThermostatInfo:gsub("%,}", "}") --Add this to replace ,} with } for valid JSON string

jsonThermostatInfo = json:decode(ThermostatInfo)
qwerk
Posts: 222
Joined: Tuesday 22 July 2014 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by qwerk »

Hello, I Hacked my Toon and it is working Domoticz.
thanks for that !!

on my main screen I have two errors .
An explanation mark in my WiFi symbol
And an warning sign ,that has to do with not reaching Eneco.

does anyone know a way to remove these?
marcelr
Posts: 42
Joined: Friday 22 May 2015 21:10
Target OS: Linux
Domoticz version: svn 2470
Location: Ehv, NL
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by marcelr »

qwerk
Posts: 222
Joined: Tuesday 22 July 2014 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by qwerk »

marcelr wrote: Sunday 13 August 2017 15:11 Check out this link:

https://www.domoticaforum.eu/viewtopic. ... 165#p77792
thank you , my error on the WiFi sign is gone.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest