Re: Controlling Toon [HACKED] from Domoticz
Posted: Tuesday 19 February 2019 10:27
Is the first post of this thread being updated if needed? Or should I go through the whole thread to find updates?
Open source Home Automation System
https://forum.domoticz.com/
change it to-- Update the thermostat sensor to current setpoint
if domoticz.devices(ToonThermostat).setPoint*100 ~= currentSetpoint*100 then
-- domoticz.log('Updating thermostat sensor to new set point: ' ..currentSetpoint)
domoticz.devices(ToonThermostat).updateSetPoint(currentSetpoint).silent()
end
-- Update the thermostat sensor to current setpoint
if domoticz.devices(ToonThermostat).setPoint*100 ~= currentSetpoint*100 then
-- domoticz.log('Updating thermostat sensor to new set point: ' ..currentSetpoint)
domoticz.variables('UV_ToonChangedByDomoticz').set(1)
domoticz.devices(ToonThermostat).updateSetPoint(currentSetpoint).silent()
end
-- 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
This is my latest script with a lot of functionalities. Just comment out what you do not need and adjust to your own system settingsEdwinK wrote: Tuesday 01 October 2019 10:59 What is the latest version of the script? Going through this site (and another) I see several scripts for a rooted/hacked Toon, and I'm getting a bit (loads) confused.
Code: Select all
return {
logging = {
level = domoticz.LOG_FORCE, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log level
marker = "-=# P1 Toon #=-"
},
on = {
timer = {
'every minute'
}
},
execute = function(domoticz)
local ToonThermostat = domoticz.variables('UV_ToonThermostat').value -- Sensor showing current setpoint
local ToonTemperature = domoticz.variables('UV_ToonTemperature').value -- Sensor showing current room temperature
local ToonBoilerTempIn = domoticz.variables('UV_ToonBoilerTempIn').value -- Sensor showing water temp return
local ToonBoilerTempOut = domoticz.variables('UV_ToonBoilerTempOut').value -- Sensor showing current water temp out
local ToonBoilerPressure = domoticz.variables('UV_ToonBoilerPressure').value -- Sensor showing current room temperature
local ToonBoilerModulation = domoticz.variables('UV_ToonBoilerModulation').value -- Sensor showing current Boiler Modulation
local ToonScenes = domoticz.variables('UV_ToonScenes').value -- Sensor showing current program
local ToonAutoProgram = domoticz.variables('UV_ToonAutoProgram').value -- Sensor showing current auto program status
local ToonProgramInformation = domoticz.variables('UV_ToonProgramInformation').value -- Sensor showing displaying program information status
local ToonIP = domoticz.variables('UV_ToonIP').value
local DomoticzIP = domoticz.variables('UV_DomoticzIP').value
local ToonBurnerName = domoticz.variables('UV_ToonBurnerName').value
local P1SmartMeterPower = domoticz.variables('UV_P1SmartMeterElectra').value
local P1SmartMeterGas1 = domoticz.variables('UV_P1SmartMeterGasMeterStand').value
local ToonBoilerSetpoint = domoticz.variables('UV_ToonBoilerTempSetpoint').value -- Sensor showing current boiler set point water temp out
-- Handle json
-- local json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local json = assert(loadfile "/var/domoticz/scripts/lua/JSON.lua")() -- For Linux (ClearOS)
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_2.", "dev_2")
GasPowerInfo = string.gsub(GasPowerInfo, "dev_2:", "dev_2\":")
local jsonGasPower = json:decode(GasPowerInfo)
-- Update the powerconsumption
local CurrentElectricityFlowHoog = tonumber(jsonGasPower.dev_24.CurrentElectricityFlow ) --stroomverbruik momenteel hoogtarief
local CurrentElectricityFlowLaag = tonumber(jsonGasPower.dev_26.CurrentElectricityFlow ) --stroomverbruik momenteel laagtarief
local CurrentElectricityQuantityHoog = tonumber(jsonGasPower.dev_24.CurrentElectricityQuantity) --stroomverbruik totaal hoogtarief
local CurrentElectricityQuantityLaag = tonumber(jsonGasPower.dev_26.CurrentElectricityQuantity) --stroomverbruik totaal laagtarief
local CurrentElectricityDeliveredHoog = tonumber(jsonGasPower.dev_25.CurrentElectricityQuantity) --stroomgeleverd momenteel hoogtarief
local CurrentElectricityDeliveredLaag = tonumber(jsonGasPower.dev_27.CurrentElectricityQuantity) --stroomgeleverd momenteel laagtarief
local CurrentElectricityQuantity = CurrentElectricityFlowHoog + CurrentElectricityFlowLaag --stroomverbruik totaal aktueel
local totalDeliveredPower = 0
local totalDeliveredPower2 = CurrentElectricityDeliveredHoog/1000 + CurrentElectricityDeliveredLaag/1000 --stroomverbruik totaal geleverd
local CurrentGasFlow = tonumber(jsonGasPower.dev_21.CurrentGasFlow)
local CurrentGasQuantity = tonumber(jsonGasPower.dev_21.CurrentGasQuantity)
domoticz.devices(P1SmartMeterPower).updateP1(CurrentElectricityQuantityLaag, CurrentElectricityQuantityHoog, CurrentElectricityDeliveredLaag, CurrentElectricityDeliveredHoog, CurrentElectricityQuantity, totalDeliveredPower).silent()
domoticz.devices(P1SmartMeterGas1).updateGas(CurrentGasQuantity).silent()
--domoticz.log('*** P1 from toon: ' .. CurrentElectricityQuantityLaag/1000 .. 'kwh USAGE1 | ' ..CurrentElectricityQuantityHoog/1000 .. 'kwh USAGE2 | ' .. CurrentElectricityDeliveredLaag/1000 .. 'kwh RETURN1 | ' .. CurrentElectricityDeliveredHoog/1000 .. 'kwh RETURN2 | ' .. CurrentElectricityQuantity .. 'w consumed | '.. totalDeliveredPower2 .. 'w produced', domoticz.LOG_FORCE)
-- 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('Updating Boiler Water In to current value: ' ..currentboilerInTemp)
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('Updating Boiler Water Out to current value: ' ..currentboilerOutTemp)
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)._nValue,0) ~= domoticz.utils.round(currentBoilerPressure,0) then
domoticz.log('Updating Boiler Pressure to current value: ' ..currentBoilerPressure, domoticz.LOG_INFO)
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)
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
-- Update the current scene by temperature
local currentActiveTemp = tonumber(jsonThermostatInfo.currentSetpoint) / 100
if currentActiveTemp == 20.5 then currentActiveState = 40 -- Comfort
elseif currentActiveTemp == 19.5 then currentActiveState = 30 -- Home
elseif currentActiveTemp == 17 then currentActiveState = 20 -- Sleep
elseif currentActiveTemp == 18.5 then currentActiveState = 10 -- Away
else currentActiveState = 50 -- Manual
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('Updating Toon burner info:')
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('Updating the Modulation sensor to new value: ' ..currentModulationLevel)
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('Updating the Boiler internal temperature setpoint to new value: ' ..currentInternalBoilerSetpoint)
domoticz.devices(ToonBoilerSetpoint).updateTemperature(currentInternalBoilerSetpoint)
end
-- Update the thermostat sensor to current setpoint
if domoticz.devices(ToonThermostat).setPoint*100 ~= currentSetpoint*100 then
domoticz.log('Updating thermostat sensor to new set point: ' ..currentSetpoint)
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('Updating the temperature sensor to new value: ' ..currentTemperature)
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('Updating Toon Scenes selector to: '..currentActiveState)
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('Updating Toon Auto Program selector to: '..currentProgramState)
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
}Code: Select all
return {
on = {
devices = {
'Toon Thermostaat'
}
},
execute = function(domoticz, device)
domoticz.openURL(string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', domoticz.variables('UV_ToonIP').value, device.setPoint*100))
domoticz.log('Setting Toon setpoint to '.. device.setPoint)
end
}madpatrick wrote: Friday 04 October 2019 21:01 This is my latest script with a lot of functionalities.
Just comment out what you do not need and adjust to your own system settings
Toon_scriptCode: Select all
CODE STARTS -- JSON data from Toon contains a extra "." which should not be there. GasPowerInfo = string.gsub(GasPowerInfo, "dev_2.", "dev_2") GasPowerInfo = string.gsub(GasPowerInfo, "dev_2:", "dev_2\":") local jsonGasPower = json:decode(GasPowerInfo) -- Update the powerconsumption local CurrentElectricityFlowHoog = tonumber(jsonGasPower.dev_24.CurrentElectricityFlow ) --stroomverbruik momenteel hoogtarief local CurrentElectricityFlowLaag = tonumber(jsonGasPower.dev_26.CurrentElectricityFlow ) --stroomverbruik momenteel laagtarief local CurrentElectricityQuantityHoog = tonumber(jsonGasPower.dev_24.CurrentElectricityQuantity) --stroomverbruik totaal hoogtarief local CurrentElectricityQuantityLaag = tonumber(jsonGasPower.dev_26.CurrentElectricityQuantity) --stroomverbruik totaal laagtarief local CurrentElectricityDeliveredHoog = tonumber(jsonGasPower.dev_25.CurrentElectricityQuantity) --stroomgeleverd momenteel hoogtarief local CurrentElectricityDeliveredLaag = tonumber(jsonGasPower.dev_27.CurrentElectricityQuantity) --stroomgeleverd momenteel laagtarief local CurrentElectricityQuantity = CurrentElectricityFlowHoog + CurrentElectricityFlowLaag --stroomverbruik totaal aktueel local totalDeliveredPower = 0 local totalDeliveredPower2 = CurrentElectricityDeliveredHoog/1000 + CurrentElectricityDeliveredLaag/1000 --stroomverbruik totaal geleverd local CurrentGasFlow = tonumber(jsonGasPower.dev_21.CurrentGasFlow) local CurrentGasQuantity = tonumber(jsonGasPower.dev_21.CurrentGasQuantity) MORE CODE }
Code: Select all
-- JSON data from Toon contains a extra "." which should not be there.
GasPowerInfo = string.gsub(GasPowerInfo, "dev_5.", "dev_5")
GasPowerInfo = string.gsub(GasPowerInfo, "dev_5:", "dev_5\":")
local jsonGasPower = json:decode(GasPowerInfo)
-- Update the powerconsumption
local CurrentElectricityFlowHoog = tonumber(jsonGasPower.dev_52.CurrentElectricityFlow ) --stroomverbruik momenteel hoogtarief
You can set the logging on DEBUG level in the script.Peebee01 wrote: Thursday 10 October 2019 8:14 s there a way to modify the script to write more details into the log? After reading the thermostat info, json is used to decode the information and update the user variables. Can I add the option to write the “ThermostatInfo” to the log before and after json:decode?
Thanks!
Code: Select all
level = domoticz.LOG_FORCE, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log levelCode: Select all
return {
logging = {
level = domoticz.LOG_INFO, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log level
marker = "-=# P1 Toon #=-"
},
on = {
timer = {
'every minute'
}
},
execute = function(domoticz)
local ToonThermostat = domoticz.variables('UV_ToonThermostat').value -- Sensor showing current setpoint
local ToonTemperature = domoticz.variables('UV_ToonTemperature').value -- Sensor showing current room temperature
local ToonBoilerTempIn = domoticz.variables('UV_ToonBoilerTempIn').value -- Sensor showing water temp return
local ToonBoilerTempOut = domoticz.variables('UV_ToonBoilerTempOut').value -- Sensor showing current water temp out
local ToonBoilerPressure = domoticz.variables('UV_ToonBoilerPressure').value -- Sensor showing current room temperature
local ToonBoilerModulation = domoticz.variables('UV_ToonBoilerModulation').value -- Sensor showing current Boiler Modulation
local ToonScenes = domoticz.variables('UV_ToonScenes').value -- Sensor showing current program
local ToonAutoProgram = domoticz.variables('UV_ToonAutoProgram').value -- Sensor showing current auto program status
local ToonProgramInformation = domoticz.variables('UV_ToonProgramInformation').value -- Sensor showing displaying program information status
local ToonIP = domoticz.variables('UV_ToonIP').value
local DomoticzIP = domoticz.variables('UV_DomoticzIP').value
local ToonBurnerName = domoticz.variables('UV_ToonBurnerName').value
local P1SmartMeterPower = domoticz.variables('UV_P1SmartMeterElectra').value
local P1SmartMeterGas1 = domoticz.variables('UV_P1SmartMeterGasMeterStand').value
local ToonBoilerSetpoint = domoticz.variables('UV_ToonBoilerTempSetpoint').value -- Sensor showing current boiler set point water temp out
-- Handle json
-- local json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- local json = assert(loadfile "/var/domoticz/scripts/lua/JSON.lua")() -- For Linux (ClearOS)
json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
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_3.", "dev_3")
GasPowerInfo = string.gsub(GasPowerInfo, "dev_3:", "dev_3\":")
local jsonGasPower = json:decode(GasPowerInfo)
-- Update the powerconsumption
local CurrentElectricityFlowHoog = tonumber(jsonGasPower.dev_34.CurrentElectricityFlow ) --stroomverbruik momenteel hoogtarief
local CurrentElectricityFlowLaag = tonumber(jsonGasPower.dev_36.CurrentElectricityFlow ) --stroomverbruik momenteel laagtarief
local CurrentElectricityQuantityHoog = tonumber(jsonGasPower.dev_34.CurrentElectricityQuantity) --stroomverbruik totaal hoogtarief
local CurrentElectricityQuantityLaag = tonumber(jsonGasPower.dev_36.CurrentElectricityQuantity) --stroomverbruik totaal laagtarief
local CurrentElectricityDeliveredHoog = tonumber(jsonGasPower.dev_35.CurrentElectricityQuantity) --stroomgeleverd momenteel hoogtarief
local CurrentElectricityDeliveredLaag = tonumber(jsonGasPower.dev_37.CurrentElectricityQuantity) --stroomgeleverd momenteel laagtarief
local CurrentElectricityQuantity = CurrentElectricityFlowHoog + CurrentElectricityFlowLaag --stroomverbruik totaal aktueel
local totalDeliveredPower = 0
local totalDeliveredPower2 = CurrentElectricityDeliveredHoog/1000 + CurrentElectricityDeliveredLaag/1000 --stroomverbruik totaal geleverd
local CurrentGasFlow = tonumber(jsonGasPower.dev_31.CurrentGasFlow)
local CurrentGasQuantity = tonumber(jsonGasPower.dev_31.CurrentGasQuantity)
domoticz.devices(P1SmartMeterPower).updateP1(CurrentElectricityQuantityLaag, CurrentElectricityQuantityHoog, CurrentElectricityDeliveredLaag, CurrentElectricityDeliveredHoog, CurrentElectricityQuantity, totalDeliveredPower).silent()
domoticz.devices(P1SmartMeterGas1).updateGas(CurrentGasQuantity).silent()
--domoticz.log('*** P1 from toon: ' .. CurrentElectricityQuantityLaag/1000 .. 'kwh USAGE1 | ' ..CurrentElectricityQuantityHoog/1000 .. 'kwh USAGE2 | ' .. CurrentElectricityDeliveredLaag/1000 .. 'kwh RETURN1 | ' .. CurrentElectricityDeliveredHoog/1000 .. 'kwh RETURN2 | ' .. CurrentElectricityQuantity .. 'w consumed | '.. totalDeliveredPower2 .. 'w produced', domoticz.LOG_FORCE)
-- 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('Updating Boiler Water In to current value: ' ..currentboilerInTemp)
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('Updating Boiler Water Out to current value: ' ..currentboilerOutTemp)
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)._nValue,0) ~= domoticz.utils.round(currentBoilerPressure,0) then
domoticz.log('Updating Boiler Pressure to current value: ' ..currentBoilerPressure, domoticz.LOG_INFO)
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)
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
-- Update the current scene by temperature
local currentActiveTemp = tonumber(jsonThermostatInfo.currentSetpoint) / 100
if currentActiveTemp == 20.5 then currentActiveState = 40 -- Comfort
elseif currentActiveTemp == 19.5 then currentActiveState = 30 -- Home
elseif currentActiveTemp == 17 then currentActiveState = 20 -- Sleep
elseif currentActiveTemp == 18.5 then currentActiveState = 10 -- Away
else currentActiveState = 50 -- Manual
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('Updating Toon burner info:')
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('Updating the Modulation sensor to new value: ' ..currentModulationLevel)
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('Updating the Boiler internal temperature setpoint to new value: ' ..currentInternalBoilerSetpoint)
domoticz.devices(ToonBoilerSetpoint).updateTemperature(currentInternalBoilerSetpoint)
end
-- Update the thermostat sensor to current setpoint
if domoticz.devices(ToonThermostat).setPoint*100 ~= currentSetpoint*100 then
domoticz.log('Updating thermostat sensor to new set point: ' ..currentSetpoint)
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('Updating the temperature sensor to new value: ' ..currentTemperature)
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('Updating Toon Scenes selector to: '..currentActiveState)
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('Updating Toon Auto Program selector to: '..currentProgramState)
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
}
Code: Select all
2019-10-11 20:52:00.147 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2019-10-11 20:52:00.149 Status: dzVents: Debug: Event triggers:
2019-10-11 20:52:00.149 Status: dzVents: Debug: - Timer
2019-10-11 20:52:00.169 Status: dzVents: Info: -=# P1 Toon #=-: ------ Start internal script: Script #6:, trigger: every minute
2019-10-11 20:52:00.307 Status: dzVents: Error (2.4.19): -=# P1 Toon #=-: There is no device with that name or id:
2019-10-11 20:52:00.307 Status: dzVents: Error (2.4.19): -=# P1 Toon #=-: An error occured when calling event handler Script #6
2019-10-11 20:52:00.307 Status: dzVents: Error (2.4.19): -=# P1 Toon #=-: ...Domoticz\scripts\dzVents\generated_scripts/Script #6.lua:75: attempt to index a nil value
2019-10-11 20:52:00.307 Status: dzVents: Info: -=# P1 Toon #=-: ------ Finished Script #620 UV_P1SmartMeterGasMeterStand String P1 GasPeebee01 wrote: Friday 11 October 2019 21:03 Hi madpatrick,
Would you mind posting your user variables? I’ve got all I believe, but could be worth checking.
Regarding the devices, I did not understand how the devices and the user variables are linked in domoticz. The names arent identical in all cases, right? So how does a user variables update a device?