Controlling Toon via Domoticz

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

Moderators: marcelr, TheHogNL, Toonz

madpatrick
Member
Member
Posts: 100
Joined: Wed Dec 06, 2017 9:52 pm
Location: Zuid-Holland

Re: Controlling Toon via Domoticz

Post by madpatrick »

Not sure if i can follow your question and scripts.
Are those all separate scripts ? If you, disable them and enable them one by one to see which script gives the error.

Dev_37 is mentioning : "CurrentElectricityFlow": "0.00" in your output of http://TOON IP/hdrv_zwave?action=getDevices.json
I believe dev_37 is for Solar panels ?
TgF2004NL
Starting Member
Starting Member
Posts: 2
Joined: Thu Apr 15, 2021 4:29 pm

Re: Controlling Toon via Domoticz

Post by TgF2004NL »

madpatrick wrote:Not sure if i can follow your question and scripts.
Are those all separate scripts ? If you, disable them and enable them one by one to see which script gives the error.

Dev_37 is mentioning : "CurrentElectricityFlow": "0.00" in your output of http://TOON IP/hdrv_zwave?action=getDevices.json
I believe dev_37 is for Solar panels ?
I'm currently using one of your scripts, found on domoticz.com (I think) and fixed the dev errors. I do have solar panels, so will try using dev_37 tomorrow. Still get some funny readings on my boiler pressure (1.6 bar) and gas usage for one day, but I think I have to try using the other dev values while looking at my Toon :-)

This is your script I'm using now:

Code: Select all

-- Toon script for rooted TOON systems
-- credits: user madpatrick from domticz.com forum
-- version 1.01 
-- date 15042021
-- script runs every 1 minute

	local scriptVersion = 'Versie 1.01 '
	local scriptVar     = '-=# TOON Script #=-'

return {
        on      = { timer = {'every minute'},
        },
logging = { level  = domoticz.LOG_ERROR,
       		marker = scriptVar },

execute = function(domoticz)
        local ToonThermostat        = 'Toon Thermostaat'                                       --   Sensor showing setpoint (thermostaat waarde van Toon)
        local ToonTemperature       = 'Temperatuur Kamer'                                      --   Sensor showing room temperature
        local ToonAutoProgram       = 'Toon Auto Program'                                      --   Sensor showing auto program status
        local ToonBoilerModulation  = 'ModulationLevel'                                        -- * Sensor showing Boiler Modulation
        local ToonScenes            = 'Toon Scenes'                                            -- * Sensor showing program
        local ToonBoilerSetpoint    = 'Ketel Setpoint'                                         -- * Sensor showing boiler temperature set point
        local ToonBoilerTempIn      = 'Ketel Temp IN'                                          -- * Sensor showing water temp return
        local ToonBoilerTempOut     = 'Ketel Temp UIT'                                         -- * Sensor showing water temp out
        local ToonBoilerPressure    = 'Keteldruk'                                              --   Sensor showing boilerpressure
        local ToonBurnerName        = 'Ketelstand'                                             --   Sensor showing boiler modus
        local P1SmartMeterPower     = 'P1 Elektra'                                             --   Sensor Energy consumption
        local P1SmartMeterGas1      = 'P1 Gas'                                                 --   Sensor Gas consumption
        local ToonIP                = '192.168.2.xxx                                          -- IP address of your Toon
        local DomoticzIP            = '192.168.2.xxx:xxxx'                                     -- IP address and portnumber of your Domoticz server
        local SetPointAway          = 18.5                                                     -- temperature of setpoint Away
        local SetPointSleep         = 17.0                                                     -- temperature of setpoint Sleep
        local SetPointHome          = 20.0                                                     -- temperature of setpoint Home
        local SetPointComfort       = 20.5                                                     -- temperature of setpoint Comfort
        local ToonProgramInformation= 'ToonProgramInformation'                                 --   Sensor showing current Program
    
-- Handle json
    -- Choose the correct platform which Domoticz runs on
        -- Remove -- before the line which applies for your situation, set -- for all other platforms
        -- local json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Raspberry
        -- local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
        -- local json = assert(loadfile "/var/domoticz/scripts/lua/JSON.lua")()  -- For Linux (ClearOS)
        local json = assert(loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")() -- For Synology
        
        local handle = assert(io.popen(string.format('curl http://%s/happ_thermstat?action=getThermostatInfo', ToonIP)))
        local ThermostatInfo = handle:read('*all')
        handle:close()
        
        local jsonThermostatInfo = json:decode(ThermostatInfo)
           if jsonThermostatInfo == nil then
           return
        end
        
        local handle2 = assert(io.popen(string.format('curl http://%s/boilerstatus/boilervalues.txt', ToonIP)))
        local BoilerInfo = handle2:read('*all')
        handle2:close()

-- JSON data from Toon contains a extra "," which should not be there.
        BoilerInfo = string.gsub(BoilerInfo, ",}", "}")
        jsonBoilerInfo = json:decode(BoilerInfo)
        
-- http://IP_TOON/hdrv_zwave?action=getDevices.json 
        local handle4 = assert(io.popen(string.format('curl http://%s/hdrv_zwave?action=getDevices.json', ToonIP)))
        local GasPowerInfo = handle4:read('*all')
        handle4:close()
        
-- JSON data from Toon contains a extra "." which should not be there.
        GasPowerInfo = string.gsub(GasPowerInfo, "dev_4.", "dev_4")         -- match your device numbers according to your own config
        GasPowerInfo = string.gsub(GasPowerInfo, "dev_4:", "dev_4\":")      -- match your device numbers according to your own config
        local jsonGasPower = json:decode(GasPowerInfo)
        
-- Update the powerconsumption
        local CurrentElectricityFlowHoog            = tonumber(jsonGasPower.dev_44.CurrentElectricityFlow)                      --stroomverbruik momenteel hoogtarief
        local CurrentElectricityFlowLaag            = tonumber(jsonGasPower.dev_45.CurrentElectricityFlow)                      --stroomverbruik momenteel laagtarief

        local CurrentElectricityQuantityHoog        = tonumber(jsonGasPower.dev_44.CurrentElectricityQuantity)                  --stroomverbruik totaal hoogtarief
        local CurrentElectricityQuantityLaag        = tonumber(jsonGasPower.dev_45.CurrentElectricityQuantity)                  --stroomverbruik totaal laagtarief
         
        local CurrentElectricityDeliveredHoog       = tonumber(jsonGasPower.dev_46.CurrentElectricityQuantity)                  --stroomgeleverd momenteel hoogtarief
        local CurrentElectricityDeliveredLaag       = tonumber(jsonGasPower.dev_47.CurrentElectricityQuantity)                  --stroomgeleverd momenteel laagtarief   
        
        local CurrentElectricityDeliveredFlowHoog   = tonumber(jsonGasPower.dev_46.CurrentElectricityFlow)                      --stroomgeleverd momenteel laagtarief
        local CurrentElectricityDeliveredFlowLaag   = tonumber(jsonGasPower.dev_47.CurrentElectricityFlow)                      --stroomgeleverd momenteel hoogtarief
         
        local PowerConsumption                      = CurrentElectricityFlowHoog + CurrentElectricityFlowLaag                   --stroomverbruik totaal aktueel
        local PowerProduction                       = CurrentElectricityDeliveredFlowHoog + CurrentElectricityDeliveredFlowLaag --stroomverbruik totaal geleverd
        
                --USAGE1= energy usage meter tariff 1
                --USAGE2= energy usage meter tariff 2
                --RETURN1= energy return meter tariff 1
                --RETURN2= energy return meter tariff 2
                --CONS= actual usage power (Watt)
                --PROD= actual return power (Watt)
                --updateP1(usage1, usage2, return1, return2, cons, prod): Function. Updates the device. Supports command options. 
        domoticz.devices(P1SmartMeterPower).updateP1(CurrentElectricityQuantityLaag, CurrentElectricityQuantityHoog, CurrentElectricityDeliveredLaag, CurrentElectricityDeliveredHoog, PowerConsumption, PowerProduction).silent()
      domoticz.log('P1 : Meter Verbruik laagtarief  : ' .. CurrentElectricityQuantityLaag/1000 .. ' kWh ', domoticz.LOG_FORCE)
      domoticz.log('P1 : Meter Verbruik hoogtarief  : ' .. CurrentElectricityQuantityHoog/1000 .. ' kWh', domoticz.LOG_FORCE)
      domoticz.log('P1 : Meter Levering laagtarief  : ' .. CurrentElectricityDeliveredLaag/1000 .. ' kWh', domoticz.LOG_FORCE)
      domoticz.log('P1 : Meter Levering hoogtarief  : ' .. CurrentElectricityDeliveredHoog/1000 .. ' kWh', domoticz.LOG_FORCE)
    
        domoticz.log('P1 : Huidig Stroom Verbruik     : ' .. PowerConsumption .. ' W', domoticz.LOG_FORCE)
        domoticz.log('P1 : Huidig Stroom Opbrengst    : ' .. PowerProduction .. ' W', domoticz.LOG_FORCE)

-- Update the gasconsumption
        local CurrentGasFlow                   = tonumber(jsonGasPower.dev_41.CurrentGasFlow)
        local CurrentGasQuantity               = tonumber(jsonGasPower.dev_41.CurrentGasQuantity)
        domoticz.devices(P1SmartMeterGas1).updateGas(CurrentGasQuantity).silent()   

-- Update the Boiler Water In to current value
  --      local currentboilerInTemp = tonumber(jsonBoilerInfo.boilerInTemp)
 --             currentboilerInTemp = tonumber(string.format("%.0f", currentboilerInTemp))  -- afgeronde getallen is voldoende [PdB]
  --      if domoticz.utils.round(domoticz.devices(ToonBoilerTempIn).temperature,0) ~= domoticz.utils.round(currentboilerInTemp,0) then
  --         domoticz.log('Update van de CV-water temperatuur IN: ' ..currentboilerInTemp .. ' °C',domoticz.LOG_INFO)
  --         domoticz.devices(ToonBoilerTempIn).updateTemperature(currentboilerInTemp).silent()
  --      end
        
-- Update the Boiler water Out to current value
 --       local currentboilerOutTemp = tonumber(jsonBoilerInfo.boilerOutTemp)
  --            currentboilerOutTemp = tonumber(string.format("%.0f", currentboilerOutTemp))  -- afgeronde getallen is voldoende [PdB]
  --      if domoticz.utils.round(domoticz.devices(ToonBoilerTempOut).temperature,0) ~= domoticz.utils.round(currentboilerOutTemp,0) then
  --          domoticz.log('Update van de CV-water temperatuur UIT : ' ..currentboilerOutTemp .. ' °C',domoticz.LOG_INFO)
 --           domoticz.devices(ToonBoilerTempOut).updateTemperature(currentboilerOutTemp).silent()
 --       end

-- Update the Boiler water Pressure to current value
        local currentBoilerPressure = tonumber(jsonBoilerInfo.boilerPressure)
              currentBoilerPressure = tonumber(string.format("%.1f", currentBoilerPressure))  -- 1 decimaal is voldoende [PdB]
        if domoticz.utils.round(domoticz.devices(ToonBoilerPressure).sValue,1) ~= domoticz.utils.round(currentBoilerPressure,1) then
           domoticz.log('Update van de waterdruk : ' ..currentBoilerPressure .. ' bar',domoticz.LOG_FORCE)
           domoticz.devices(ToonBoilerPressure).updatePressure(currentBoilerPressure).silent()
        end

-- Update the current temperature setpoint
        local currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100
        local currentTemperature = tonumber(jsonThermostatInfo.currentTemp) / 100
              currentTemperature = tonumber(string.format("%.1f", currentTemperature))  -- 1 decimaal is voldoende [PdB]
              
-- Update the current auto program
        local currentProgramState = tonumber(jsonThermostatInfo.programState)
                    if currentProgramState == 0 then currentProgramState = 10 -- No
                elseif currentProgramState == 1 then currentProgramState = 20 -- Yes
                elseif currentProgramState == 2 then currentProgramState = 30 -- Temporary       
            end
            
-- Update the current scene by state
        local currentActiveState = tonumber(jsonThermostatInfo.activeState)
        
-- Update the current scene by temperature
		local currentActiveTemp = tonumber(jsonThermostatInfo.currentSetpoint) / 100

                    if currentActiveState == 0 or currentActiveTemp == SetPointComfort  then currentActiveState = 40     -- Comfort
                elseif currentActiveState == 1 or currentActiveTemp == SetPointHome     then currentActiveState = 30     -- Home
                elseif currentActiveState == 2 or currentActiveTemp == SetPointSleep    then currentActiveState = 20     -- Sleep
                elseif currentActiveState == 3 or currentActiveTemp == SetPointAway     then currentActiveState = 10     -- Away
                elseif currentActiveState == -1 then currentActiveState = 50 -- Manual                    
                    
                --domoticz.log('Update Toon scene door temperature of Scene wijziging : ' ..currentActiveState,domoticz.LOG_FORCE)
            end     
            
-- Update the toon burner selector to current program state
        local currentBurnerInfo = tonumber(jsonThermostatInfo.burnerInfo)   
        local CurrentToonBurnerValue = domoticz.devices(ToonBurnerName).level
            if currentBurnerInfo == 0 then currentBurnerInfo = 0                    -- uit
        elseif currentBurnerInfo == 1 then currentBurnerInfo = 10                   -- cv aan
        elseif currentBurnerInfo == 2 then currentBurnerInfo = 20                   -- warmwater aan
--        elseif currentBurnerInfo == 3 then currentBurnerInfo = 30                 -- voorverwarmen volgend setpoint
        end
        
-- Update toon burner selector if it has changed            
        if CurrentToonBurnerValue ~= currentBurnerInfo then  
            domoticz.log('Update van de ketelstand: ' ..currentBurnerInfo,domoticz.LOG_FORCE)
            domoticz.devices(ToonBurnerName).switchSelector(currentBurnerInfo)
        end
                    
-- Update the modulation level of the burner
        local currentModulationLevel = tonumber(jsonThermostatInfo.currentModulationLevel)
        if domoticz.devices(ToonBoilerModulation).percentage + 1 ~= currentModulationLevel + 1 then 
            domoticz.log('Update van de Modulatie stand: ' ..currentModulationLevel .. ' %',domoticz.LOG_FORCE)
            domoticz.devices(ToonBoilerModulation).updatePercentage(currentModulationLevel)
        end
        
-- Update the temperature Boiler setpoint to current boiler set point
         local currentInternalBoilerSetpoint = jsonThermostatInfo.currentInternalBoilerSetpoint+1
        if domoticz.utils.round(domoticz.devices(ToonBoilerSetpoint).temperature, 1) ~= domoticz.utils.round(currentInternalBoilerSetpoint, 1) then 
            domoticz.log('Update van het ketelwater temperatuur setpunt: ' ..currentInternalBoilerSetpoint .. ' °C',domoticz.LOG_FORCE)
            domoticz.devices(ToonBoilerSetpoint).updateTemperature(currentInternalBoilerSetpoint)
        end
        
-- Update the thermostat sensor to current setpoint
        if domoticz.devices(ToonThermostat).setPoint*100 ~= currentSetpoint*100 then
            domoticz.log('Update van de temperatuur instelling naar: ' ..currentSetpoint .. ' °C',domoticz.LOG_FORCE)
            domoticz.devices(ToonThermostat).updateSetPoint(currentSetpoint).silent()
        end
     
-- Update the temperature sensor to current room temperature
        if domoticz.utils.round(domoticz.devices(ToonTemperature).temperature, 1) ~= domoticz.utils.round(currentTemperature, 1) then 
            domoticz.log('Update van de Kamertemparatuur : ' ..currentTemperature .. ' °C',domoticz.LOG_FORCE)
            domoticz.devices(ToonTemperature).updateTemperature(currentTemperature)
        end
        
-- Update the toon scene selector sensor to current program state
        if domoticz.devices(ToonScenes).level ~= currentActiveState then  -- Update toon selector if it has changed
            domoticz.log('Update van de Toon Scene : '..currentActiveState,domoticz.LOG_FORCE)
            domoticz.devices(ToonScenes).switchSelector(currentActiveState).silent()
        end
        
-- Updates the toon auto program switch 
        if domoticz.devices(ToonAutoProgram).level ~= currentProgramState then -- Update toon auto program selector if it has changed
            domoticz.log('Update van het Toon Auto Program : '..currentProgramState,domoticz.LOG_FORCE)
            domoticz.devices(ToonAutoProgram).switchSelector(currentProgramState).silent()
        end
-- Updates the toon program information text box
		local currentNextTime = jsonThermostatInfo.nextTime
		local currentNextSetPoint = tonumber(jsonThermostatInfo.nextSetpoint) / 100
		
		if currentNextTime == 0 or currentNextSetPoint == 0 then
			ToonProgramInformationSensorValue = 'Op ' ..currentSetpoint.. '°'
		else
			ToonProgramInformationSensorValue = 'Om ' ..os.date('%H:%M', currentNextTime).. ' op ' ..currentNextSetPoint.. '°'
		end
		
		if domoticz.devices(ToonProgramInformation).text ~= ToonProgramInformationSensorValue then
			-- domoticz.log('Updating Toon Program Information to: '..ToonProgramInformationSensorValue)
			domoticz.devices(ToonProgramInformation).updateText(ToonProgramInformationSensorValue)
		end
   end
}
If you have any feedback: allways welcome!
Last edited by TgF2004NL on Sat Apr 17, 2021 12:08 am, edited 1 time in total.
oepi-loepi
Advanced Member
Advanced Member
Posts: 505
Joined: Sat Feb 09, 2019 7:18 pm

Re: Controlling Toon via Domoticz

Post by oepi-loepi »

I think you forgot to post a script. The data collector script you have send is not 64 lines long.. so there is another lua script.
Edwin66
Member
Member
Posts: 78
Joined: Mon Aug 13, 2018 10:50 pm

Re: Controlling Toon via Domoticz

Post by Edwin66 »

madpatrick wrote:Sure,

Please be aware for the Uservariables etc..... I've changed the names to more logical names
Also i've extended the script with more functionalities. If you do not needed them you can comment them out (or delete)
So, now that the seasons are changing once again to colder temperature, I'm glad I found this (again). This time I hope that Toon and Domoticz will keep playing nice with each other.

Once again, my thanks.
Toon® (rooted) | Hue bulbs | TRÅDFRI bulbs | Smart Plug | Domoticz latest BETA |

I'm not a programmer, just wish things work MY way
TommieNL
Starting Member
Starting Member
Posts: 8
Joined: Thu May 14, 2020 3:00 pm

Re: Controlling Toon via Domoticz

Post by TommieNL »

HI, thanks for the script! I'm trying to implement this again after receiving a toonv2. I'm running Linux (Ubuntu) and i've set the json = assert(loadfile to ` /home/user/domoticz/scripts/lua/JSON.lua`. But after the script Domoticz stops working / chrashes.

Any idea what this could be? Something to di with file rights maybe?
Edwin66
Member
Member
Posts: 78
Joined: Mon Aug 13, 2018 10:50 pm

Re: Controlling Toon via Domoticz

Post by Edwin66 »

I don't know why, but I keep forgetting the dev_ number for my Toon1.
Toon® (rooted) | Hue bulbs | TRÅDFRI bulbs | Smart Plug | Domoticz latest BETA |

I'm not a programmer, just wish things work MY way
madpatrick
Member
Member
Posts: 100
Joined: Wed Dec 06, 2017 9:52 pm
Location: Zuid-Holland

Re: Controlling Toon via Domoticz

Post by madpatrick »

Try

Code: Select all

 http://127.0.0.1/hdrv_zwave?action=getDevices.json 
See also
https://www.domoticz.com/forum/viewtopi ... 95#p136695



Google does wonders if you need to find something :)
ikookmaar
Starting Member
Starting Member
Posts: 30
Joined: Tue Mar 12, 2019 11:29 pm

Re: Controlling Toon via Domoticz

Post by ikookmaar »

Hi. Did anyone manage to get the Toon2 values from the humidity sensor into Domoticz?
I am not much of a programmer, but added / changed something to the script, simular to what was used for the modulation level of the burner:

Code: Select all


execute = function(domoticz)
     ... (snip)..
    [b] local ToonHumidity = domoticz.variables('UV_ToonHumiditySensorName').value -- Sensor showing current room humidity percentage[/b]

-- Handle json
		local json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
	... (snip)..
		[b]-- Toon2 extra sensor info
	         local handle3 = assert(io.popen(string.format('curl http://%s/tsc/sensors?action=getDevices.json', ToonIP)))
		local SensorInfo = handle3:read('*all') handle3:close()
		local jsonSensorInfo = json:decode(SensorInfo)
		
		if jsonSensorInfo == nil then
			return
		end[/b]

       [b]-- Update the Humidity percentage
      local currentHumidityLevel = tonumber(jsonSensorInfo.humidity)
	    if domoticz.devices(ToonHumidity).percentage + 1 ~= currentHumidityLevel + 1 then
	        domoticz.log('Updating the Humidity percentage sensor to new value: ' ..currentHumidityLevel
	        domoticz.devices(ToonHumidity).updatePercentage(currentHumidityLevel)
	    end
[/b]
Off course I also created a sensor:

Dummy 1409B 1 Luchtvochtigheid Binnen Humidity LaCrosse TX3

as well as a user variable of the type String:

UV_ToonHumiditySensorName = Luchtvochtigheid Binnen


Unfortunately this doesn't seem to work, and I don't know what to add to test / log exactly where it fails...
The Domoticz log throws an error at the line :

Code: Select all

 if domoticz.devices(ToonHumidity).percentage + 1 ~= currentHumidityLevel + 1 then 
"attempt to perform an arrithmetic on a nil value"


Besides none of the boiler stuff is working either anymore, so I had to comment-out all of that, as advised in https://ehoco.nl/geroote-toon-bedienen- ... mment-7467

Any help is much appreciated!
ikookmaar
Starting Member
Starting Member
Posts: 30
Joined: Tue Mar 12, 2019 11:29 pm

Re: Controlling Toon via Domoticz

Post by ikookmaar »

Never mind, it works now :D .
There was nothing wrong with the code, but I had used the wrong type of device in Domoticz.
Of course it's not really a humidity sensor type (La Crosse TX3), but a simple percentage sensor... :oops:
madpatrick
Member
Member
Posts: 100
Joined: Wed Dec 06, 2017 9:52 pm
Location: Zuid-Holland

Re: Controlling Toon via Domoticz

Post by madpatrick »

Mocht iemand he tleuk vinden om de vochtsensor uit te lezen, kan je dit toevoegen aan het script

Code: Select all

— Vochtsensor
local handle3 = assert(io.popen(string.format(‘curl http://%s//tsc/sensors‘, ToonIP)))
local TSCsensors = handle3:read(‘*all’)
handle3:close()
jsonTSCsensors = json:decode(TSCsensors)

local TSCsensors_hum = tonumber(jsonTSCsensors.humidity)
domoticz.log(‘Luchtvochtigheid: ‘ ..TSCsensors_hum ,domoticz.LOG_FORCE)
Nu schrijft hij het nog enkel in de log, maar als je een device aanmaakt kan die je dit daar mee uitlezen
Maak een dummy sensor aan met type luchtvochtigheid

Code: Select all

domoticz.devices(xxx).update(TSCsensors_hum).silent()
xxx is je devicenummer die je hebt aangemaakt
Post Reply

Return to “Toon external control”