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
-------------------------------------------------------------------------------------
Switches