Page 13 of 22

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 23 September 2018 14:11
by madpatrick
For who is interested, i've updated the current scripts since they where not working for me.
Also i've added the Boilermodulationlevel
Now it is a complete package with all the possible Toon sensors available.

1e:
- Toon_Getinfo_lua
- Lua
- Device

Code: Select all

-- Version 1:
-- 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

-- Version 2
-- 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.
-- Source: https://www.domoticz.com/forum/viewtopic.php?f=34&t=11421&start=20#p125837

-- Extra improvement:
-- Updates Toon Burner status in order to see in domoticz if your boiler is on for the hotwater or heating or off
-- Updates Toon Boiler temp
-- Updates Toon ToonboilerOutTempName Sensor to value set on Toon
-- Updates Toon ToonboilerInTempName Sensor to value set on Toon
-- Updates Toon ToonboilerPressure sensor to value set on Toon 
-- Updates Toon boilerModulationLevel sensor to value set on Toon 

commandArray = {}
-- uservariables
    ToonIP = uservariables['UV_ToonIP']
    DomoticzIP = uservariables['UV_DomoticzIP']
    ToonThermostatSensorName = uservariables['UV_ToonThermostatSensorName'] -- Sensor showing current setpoint
    ToonTemperatureSensorName = uservariables['UV_ToonTemperatureSensorName'] -- Sensor showing current room temperature
    ToonScenesSensorName  = uservariables['UV_ToonScenesSensorName'] -- Sensor showing current program
    ToonAutoProgramSensorName = uservariables['UV_ToonAutoProgramSensorName'] -- Sensor showing current auto program status
	ToonBurnerName = uservariables['UV_ToonBurnerName']
	ToonProgramInformationSensorName = uservariables['UV_ToonProgramInformationSensorName'] -- Sensor showing displaying program information status
	ToonBoilerTempSetpoint = uservariables['UV_ToonBoilerTempSetpointSensorName'] -- Sensor showing current internal boiler temp 
	ToonboilerInTempName = uservariables['UV_ToonboilerInTempName'] -- Sensor inlet temperature
    ToonboilerOutTempName = uservariables['UV_ToonboilerOutTempName'] -- Sensor outlet temperature
    ToonboilerPressure  =   uservariables['UV_ToonboilerPressure'] -- ToonboilerPressure
    ToonboilerModulationLevel = uservariables['UV_ToonboilerModulationLevel'] -- Sensor showing current Boiler Modulation Level
    
-- Choose the correct platform which Domoticz runs on
-- Remove -- before the line which applies for your situation, set -- for all other platforms
    json = assert(loadfile "/var/domoticz/scripts/lua/JSON.lua")()  -- For Linux (ClearOS)
--  json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Raspberry
--  json = assert(loadfile "/opt/domoticz/scripts/lua/JSON.lua")()  -- For Linux (LEDE)
--  json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
--  json = assert(loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")() -- For Synology
    
    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 handle = assert(io.popen(string.format('curl http://%s/boilerstatus/boilervalues.txt', ToonIP)))
        local BoilerInfo = handle:read('*all')
    handle:close()

-- JSON data from Toon contains a extra "," which should not be there.
    BoilerInfo = string.gsub(BoilerInfo, ",}", "}")
    jsonBoilerInfo = json:decode(BoilerInfo)
-- JSON data from Toon contains a extra "," which should not be there.
    ThermostatInfo = string.gsub(ThermostatInfo, ",}", "}")
    jsonThermostatInfo = json:decode(ThermostatInfo)

    currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100
    currentTemperature = tonumber(jsonThermostatInfo.currentTemp) / 100
    currentTemperature = tonumber(string.format("%.1f", currentTemperature))  -- 1 decimaal is voldoende
    currentProgramState = tonumber(jsonThermostatInfo.programState)
    currentActiveState = tonumber(jsonThermostatInfo.activeState)
    currentNextTime = jsonThermostatInfo.nextTime
    currentBurnerInfo = tonumber(jsonThermostatInfo.burnerInfo)
    currentNextSetPoint = tonumber(jsonThermostatInfo.nextSetpoint) / 100
    currentBoilerSetPoint = tonumber(jsonThermostatInfo.currentInternalBoilerSetpoint)
    currentboilerInTemp = tonumber(jsonBoilerInfo.boilerInTemp)
    currentboilerInTemp = tonumber(string.format("%.0f", currentboilerInTemp))  -- afgeronde getallen is voldoende
    currentboilerOutTemp = tonumber(jsonBoilerInfo.boilerOutTemp)
    currentboilerOutTemp = tonumber(string.format("%.0f", currentboilerOutTemp))  -- afgeronde getallen is voldoende
    currentboilerPressure = tonumber(jsonBoilerInfo.boilerPressure)
    currentboilerModulationLevel = tonumber(jsonBoilerInfo.boilerModulationLevel) --Toon Modulation Level
   
-- 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
    
-- 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
    
-- Update the toon scene selector sensor to current program state
    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
   
-- Updates the toon auto program switch
    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
   
-- Updates the toon program information text box
    CurrentToomProgramInformationSensorValue = otherdevices_svalues[ToonProgramInformationSensorName]
        if currentNextTime == 0 or currentNextSetPoint == 0 then
            ToonProgramInformationSensorValue = 'Temp : ' ..currentSetpoint.. '° / ' ..currentTemperature.. '°'
        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
            
-- Update the toon burner selector to current program state
	CurrentToonBurnerValue = otherdevices_svalues[ToonBurnerName]  
		if currentBurnerInfo == 0 then currentBurnerInfo = '0' -- uit
		    elseif currentBurnerInfo == 1 then currentBurnerInfo = '10' -- cv aan
		    elseif currentBurnerInfo == 2 then currentBurnerInfo = '20' -- warmwater aan
		end
		
		if CurrentToonBurnerValue ~= currentBurnerInfo then  -- Update toon burner selector if it has changed
			print ('Updating Toon burner info')
			commandArray[7] = {['UpdateDevice'] = string.format('%s|1|%s', otherdevices_idx[ToonBurnerName], currentBurnerInfo)}
		end

-- Update the boilerInTemp
        if otherdevices_svalues[ToonboilerInTempName]*100 ~= currentboilerInTemp*100 then  
            print('Updating boiler inlet temp to new value: ' ..currentboilerInTemp)
            commandArray[1] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerInTempName], currentboilerInTemp)}
            -- update the boilerModulationLevel
            print('Updating boiler Modulation Level to value: ' ..currentboilerModulationLevel)
            commandArray[11] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerModulationLevel], currentboilerModulationLevel)}
        end
    
-- Update the boilerOutTemp
        if otherdevices_svalues[ToonboilerOutTempName]*100 ~= currentboilerOutTemp*100 then 
            print('Updating boiler outlet temp to new value: ' ..currentboilerOutTemp)
            commandArray[2] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerOutTempName], currentboilerOutTemp)}
            -- update the boilerModulationLevel
            print('Updating boiler Modulation Level to value: ' ..currentboilerModulationLevel)
            commandArray[11] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerModulationLevel], currentboilerModulationLevel)}
        end

-- Update the boilerPressure
        if otherdevices_svalues[ToonboilerPressure]*100 ~= currentboilerPressure*100 then 
            print('Updating boiler pressure to new value: ' ..currentboilerPressure)
            commandArray[3] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerPressure], currentboilerPressure)}
        end
        
-- update the boilerModulationLevel
        --if otherdevices_svalues[ToonboilerModulationLevel]*100 ~= currentboilerModulationLevel*100 then 
        --    print('Updating boiler Modulation Level to value: ' ..currentboilerModulationLevel)
        --    commandArray[11] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonboilerModulationLevel], currentboilerModulationLevel)}
        --end
--
return commandArray
-------------------------------------------------------------------------------------

2e:
- Toon_Thermostat
- Lua
- Device

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]
                ToonCommand = string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', ToonIP, SetPoint*100)
                
                print('Setting Toon setpoint to '.. SetPoint)
                commandArray['OpenURL'] = ToonCommand
            end
        end
    end

return commandArray
-------------------------------------------------------------------------------------

User variables

Image

-------------------------------------------------------------------------------------

Switches

Image

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 21 October 2018 19:33
by francisb
Hi madpatrick,

I tried your script, but when i run the toon_getinfo_lua script i get the following in the log:

Code: Select all

Error: EventSystem: in Toon_Getinfo_lua: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed to JSON:decode(): <?xml version="1.0" encoding="iso-8859-1"?>
2018-10-21 19:31:40.343 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2018-10-21 19:31:40.343 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2018-10-21 19:31:40.343 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2018-10-21 19:31:40.343 <head>
2018-10-21 19:31:40.343 <title>404 - Not Found</title>
2018-10-21 19:31:40.343 </head>
2018-10-21 19:31:40.343 <body>
2018-10-21 19:31:40.343 <h1>404 - Not Found</h1>
2018-10-21 19:31:40.343 </body>
2018-10-21 19:31:40.343 </html>
2018-10-21 19:31:40.343 
Can you help me?

Regards,

Francis

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 21 October 2018 19:41
by madpatrick
francisb wrote: Sunday 21 October 2018 19:33 Hi madpatrick,

I tried your script, but when i run the toon_getinfo_lua script i get the following in the log:

Code: Select all

Error: EventSystem: in Toon_Getinfo_lua: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed to JSON:decode(): <?xml version="1.0" encoding="iso-8859-1"?>
2018-10-21 19:31:40.343 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2018-10-21 19:31:40.343 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2018-10-21 19:31:40.343 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2018-10-21 19:31:40.343 <head>
2018-10-21 19:31:40.343 <title>404 - Not Found</title>
2018-10-21 19:31:40.343 </head>
2018-10-21 19:31:40.343 <body>
2018-10-21 19:31:40.343 <h1>404 - Not Found</h1>
2018-10-21 19:31:40.343 </body>
2018-10-21 19:31:40.343 </html>
2018-10-21 19:31:40.343 
Can you help me?

Regards,

Francis
Hi Francis,

This is harmless. I've also something this in my log file.
It will dissapear after a few minutes.
I think it has to do will the data Toon is sending.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 21 October 2018 19:57
by EdwinK
O. Right. Need to re-add this again, since Domoticz died on me earlier.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 21 October 2018 22:12
by francisb
well, i have run this for two hours now but still the error.....

Re: Controlling Toon [HACKED] from Domoticz

Posted: Sunday 21 October 2018 22:22
by madpatrick
francisb wrote: Sunday 21 October 2018 22:12 well, i have run this for two hours now but still the error.....
Check out this comment

JSON data from Toon contains a extra "," which should not be there.

Maybe you can rwmove the extra “,”

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 22 October 2018 19:15
by francisb
nope,

now i get this:

Code: Select all

2018-10-22 19:13:51.924 Error: EventSystem: in Toon_Getinfo_lua: [string "-- Version 1:..."]:57: ')' expected near '"}"' 
Regards,

Francis

Re: Controlling Toon [HACKED] from Domoticz

Posted: Friday 02 November 2018 11:31
by tc1dft
Hoi ..my too ..

Does anyone have an idea what is?

2018-11-02 11:28:06.247 Error: EventSystem: in BoilerTemp: [string "-- Time script runs every minute, intended to..."]:43: attempt to perform arithmetic on field '?' (a nil value)
2018-11-02 11:28:06.616 Error: EventSystem: in ToonBeta: [string "-- Version 1:..."]:80: attempt to perform arithmetic on field '?' (a nil value)

Regards, Tinus
I think look over it.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Friday 02 November 2018 15:16
by EdwinK
Check if your user-variables are EXACTLY written as instructed. I made a typo in one of them, and it gave me the same error.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Friday 02 November 2018 19:42
by madpatrick
Check out this post. https://www.domoticaforum.eu/viewtopic. ... =15#p87836
This script is in DZvent and is running smoother.
If you do not use all the functions you just need to disable them.

I've disable these functions (complete block):
-- domoticz.log(jsonGasPower)
-- Update the temperature Boiler setpoint to current boiler set point

Re: Controlling Toon [HACKED] from Domoticz

Posted: Saturday 03 November 2018 9:22
by EdwinK
Seems to be using other user-variables.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Saturday 03 November 2018 9:31
by madpatrick
EdwinK wrote: Saturday 03 November 2018 9:22 Seems to be using other user-variables.
Corrrect. but you can adjust these easily

The only thing i'm not getting to work in the P1 powerconsumption and P1 Powerdelivery (solarpanels)

Re: Controlling Toon [HACKED] from Domoticz

Posted: Saturday 03 November 2018 10:19
by EdwinK
Changed them all (Almost I think). Just need to find out about those P1 variables.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Saturday 03 November 2018 10:23
by madpatrick
EdwinK wrote: Saturday 03 November 2018 10:19 Changed them all (Almost I think). Just need to find out about those P1 variables.
My Toon2 has different dev_ numbers.
Instead of dev_4 it is dev_2
So dev_44 = dev_24

Re: Controlling Toon [HACKED] from Domoticz

Posted: Saturday 03 November 2018 11:00
by EdwinK
Ah.. I have a Toon1.

thought i had it working..

Code: Select all

 There is no device with that name or id: ToonBoilerTempIn
There is..

Code: Select all

 	UV_ToonBoilerTempIn	String	ToonBoilerTempIn	2018-11-03 11:22:08
*sighs*

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 05 November 2018 11:02
by MatthijsD
I hope someone can help me out here :)
Toon suddenly stopped working on Domoticz; Room Setpoint, HeatingOn, Stroom and Temperature are all last sen on 2018-10-10 02:07:38.

I have no idea where to look how to get this working again.
Anyone had this happen to?

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 05 November 2018 11:07
by Smiggel
Did Toon perhaps get a new IP address?

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 05 November 2018 11:09
by MatthijsD
Smiggel wrote: Monday 05 November 2018 11:07 Did Toon perhaps get a new IP address?
Could be. But I can't remember ever filling in an IP adress anywhere.

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 05 November 2018 11:45
by MatthijsD
MatthijsD wrote: Monday 05 November 2018 11:02 I hope someone can help me out here :)
Toon suddenly stopped working on Domoticz; Room Setpoint, HeatingOn, Stroom and Temperature are all last sen on 2018-10-10 02:07:38.

I have no idea where to look how to get this working again.
Anyone had this happen to?
I've read the tutorial about Toon and Domoticz again, couldn't find anything out of the ordinary.
Then, I went to the Toon Hardware in Domoticz and turned it off and on again. Then suddenly it started working again!

Was lucky that this did the trick :')

Re: Controlling Toon [HACKED] from Domoticz

Posted: Monday 05 November 2018 12:28
by ronalddehaan
madpatrick wrote: Sunday 23 September 2018 14:11 snip
So this is the most recent (in a nutshell) instruction to get Toon talking to Domoticz?
In that case I will offer up a spare saturday evening to give it a new try :D