Controlling Toon via Domoticz

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

Moderators: marcelr, TerrorSource, Toonz, TheHogNL

Re: Controlling Toon via Domoticz

Postby madpatrick » Fri Apr 16, 2021 4:21 pm

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 ?
User avatar
madpatrick
Member
Member
 
Posts: 95
Joined: December 2017
Location: Zuid-Holland

Re: Controlling Toon via Domoticz

Postby TgF2004NL » Fri Apr 16, 2021 11:06 pm

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.
TgF2004NL
Starting Member
Starting Member
 
Posts: 2
Joined: April 2021

Re: Controlling Toon via Domoticz

Postby oepi-loepi » Fri Apr 16, 2021 11:07 pm

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.
oepi-loepi
Member
Member
 
Posts: 339
Joined: February 2019

Re: Controlling Toon via Domoticz

Postby Edwin66 » Mon Sep 20, 2021 1:16 pm

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
Edwin66
Member
Member
 
Posts: 76
Joined: August 2018

Previous

Return to Toon external control

Who is online

Users browsing this forum: No registered users and 1 guest