Re: Controlling Toon via Domoticz
Posted: Sat Sep 08, 2018 10:52 am
Before I could also see how much energy the plug was using on domoticz, not any more however.
Domotica - Home Automation Forum
https://www.domoticaforum.eu/
Can you make a separate topic for this? Makes it easier to find for others.mAiden wrote:For the people with smart plugs, here a detailed explanation, how to connect them to Domoticz.
This way you can also switch your plugs on time, and you are totally independent of Olisto or a Service Center.
English version comes as soon as possible .. Here the Dutch version ..
Code: Select all
- platform: command_line
switches:
switch_naam_1:
command_on: curl --data "action=basicCommand&nodeID=14&state=1" http://192.168.1.115:10080/hdrv_zwave?
command_off: curl --data "action=basicCommand&nodeID=14&state=0" http://192.168.1.115:10080/hdrv_zwave?
switch_naam_2:
command_on: curl --data "action=basicCommand&nodeID=15&state=1" http://192.168.1.115:10080/hdrv_zwave?
command_off: curl --data "action=basicCommand&nodeID=15&state=0" http://192.168.1.115:10080/hdrv_zwave?
Code: Select all
return {
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 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")
GasPowerInfo = string.gsub(GasPowerInfo, "dev_4:", "dev_4\":")
local jsonGasPower = json:decode(GasPowerInfo)
-- domoticz.log(jsonGasPower)
local CurrentElectricityFlowHoog = tonumber(jsonGasPower.dev_44.CurrentElectricityFlow )
local CurrentElectricityQuantityHoog = tonumber(jsonGasPower.dev_44.CurrentElectricityQuantity)
local CurrentElectricityFlowLaag = tonumber(jsonGasPower.dev_46.CurrentElectricityFlow )
local CurrentElectricityQuantityLaag = tonumber(jsonGasPower.dev_46.CurrentElectricityQuantity)
local CurrentGasFlow = tonumber(jsonGasPower.dev_41.CurrentGasFlow)
local CurrentGasQuantity = tonumber(jsonGasPower.dev_41.CurrentGasQuantity)
local CurrentElectricityQuantity = CurrentElectricityFlowHoog + CurrentElectricityFlowLaag
local CurrentElectricityDeliveredLaag = 0
local CurrentElectricityDeliveredHoog = 0
local totalDeliveredPower = 0
domoticz.devices(P1SmartMeterPower).updateP1(CurrentElectricityQuantityLaag, CurrentElectricityQuantityHoog, CurrentElectricityDeliveredLaag, CurrentElectricityDeliveredHoog, CurrentElectricityQuantity, totalDeliveredPower).silent()
domoticz.devices(P1SmartMeterGas1).updateGas(CurrentGasQuantity).silent()
-- Update the Boiler Water In to current value
local currentboilerInTemp = tonumber(jsonBoilerInfo.boilerInTemp)
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)
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) * 10
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.devices(ToonBoilerPressure).updatePressure(currentBoilerPressure).silent()
end
local currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100
local currentTemperature = tonumber(jsonThermostatInfo.currentTemp) / 100
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
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 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
end
if CurrentToonBurnerValue ~= currentBurnerInfo then -- Update toon burner selector if it has changed
-- 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
}
Great work !!BOverdevest wrote:Based on several posts, I combined getting all Toon data to Domoticz in a single DzVents script. So both boiler data, thermostat data and the P1 data.
Now that I have a rooted Toon2I had to update the script, as the P1 data apparently changed in the http://<ToonIP>/hdrv_zwave?action=getDevices.json.
Code: Select all
2018-10-28 17:43:00.506 Status: dzVents: Info: ------ Start internal script: Toon:, trigger: every minute
2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): An error occured when calling event handler Toon
2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): /var/domoticz/scripts/dzVents/generated_scripts/Toon.lua:58: attempt to index field 'dev_44' (a nil value)
2018-10-28 17:43:00.585 Status: dzVents: Info: ------ Finished Toon
Corrrect. but you can adjust these easilyEdwin66 wrote:Seems to be using some other user-variables.
madpatrick wrote:Corrrect. but you can adjust these easilyEdwin66 wrote:Seems to be using some other user-variables.
The only thing i'm not getting to work in the P1 powerconsumption and P1 Powerdelivery (solarpanels)
Got those at line 57, but it looks like the same error.madpatrick wrote: Only i'm not able to get the P1 meters.
I'm getting errors and then the script stops.
Code: Select all
2018-10-28 17:43:00.506 Status: dzVents: Info: ------ Start internal script: Toon:, trigger: every minute 2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): An error occured when calling event handler Toon 2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): /var/domoticz/scripts/dzVents/generated_scripts/Toon.lua:58: attempt to index field 'dev_44' (a nil value) 2018-10-28 17:43:00.585 Status: dzVents: Info: ------ Finished Toon
Try to change dev_44 to dev_24Edwin66 wrote:Got those at line 57, but it looks like the same error.madpatrick wrote: Only i'm not able to get the P1 meters.
I'm getting errors and then the script stops.
Code: Select all
2018-10-28 17:43:00.506 Status: dzVents: Info: ------ Start internal script: Toon:, trigger: every minute 2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): An error occured when calling event handler Toon 2018-10-28 17:43:00.585 Status: dzVents: Error (2.4.6): /var/domoticz/scripts/dzVents/generated_scripts/Toon.lua:58: attempt to index field 'dev_44' (a nil value) 2018-10-28 17:43:00.585 Status: dzVents: Info: ------ Finished Toon
Code: Select all
018-11-04 09:30:00.070 Status: dzVents: Info: ------ Start internal script: TOON:, trigger: every minute
2018-11-04 09:30:00.463 Status: dzVents: Info: {["dev_2.1"]={["CurrentGasQuantity"]="672281.00", ["internalAddress"]="2.1", ["name"]="HAE_METER_v3_1", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="f2393423-dde2-4f30-a5ea-561a19361126", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["CurrentGasFlow"]="422.00", ["DeviceName"]="HAE_METER_v3_1", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_1", ["nodeFlags"]={}}, ["dev_2.2"]={["internalAddress"]="2.2", ["name"]="HAE_METER_v3_2", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="84ecf9de-3ff7-4b94-b14e-9add4e9a55c5", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_2", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_2", ["nodeFlags"]={}}, ["dev_2.5"]={["internalAddress"]="2.5", ["name"]="HAE_METER_v3_5", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="95a0485e-f462-43c4-a2b6-a58b47230f53", ["CurrentElectricityFlow"]="0.00", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_5", ["CurrentElectricityQuantity"]="0.00", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_5", ["nodeFlags"]={}}, ["dev_2.6"]={["internalAddress"]="2.6", ["name"]="HAE_METER_v3_6", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="ec38b1d6-fa71-43e6-bc36-a26acceb7c52", ["CurrentElectricityFlow"]="383.00", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_6", ["CurrentElectricityQuantity"]="2516398.00", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_6", ["nodeFlags"]={}}, ["dev_2.8"]={["internalAddress"]="2.8", ["name"]="HAE_METER_v3_8", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="95f2ab46-e8b5-4ae1-bd95-b599782e5852", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["CurrentHeatQuantity"]="NaN", ["DeviceName"]="HAE_METER_v3_8", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_8", ["nodeFlags"]={}}, ["dev_2.4"]={["internalAddress"]="2.4", ["name"]="HAE_METER_v3_4", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="ed4642ef-285a-487c-b1e5-e5fd9f7e1aa1", ["CurrentElectricityFlow"]="0.00", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_4", ["CurrentElectricityQuantity"]="2620126.00", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_4", ["nodeFlags"]={}}, ["dev_settings_device"]={["type"]="settings_device", ["internalAddress"]="settings_device", ["uuid"]="6b6a1f78-bea9-46f9-a053-87461583d393", ["name"]="settings_device"}, ["dev_2.3"]={["internalAddress"]="2.3", ["name"]="HAE_METER_v3_3", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="956d126a-a3c5-4964-91c0-1af315fb9f2c", ["CurrentElectricityFlow"]="NaN", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_3", ["CurrentElectricityQuantity"]="NaN", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_3", ["nodeFlags"]={}}, ["dev_4"]={["internalAddress"]="4", ["name"]="NAS_WR01Z-1", ["supportedCC"]="5e 72 86 85 59 5a 73 70 25 27 71 32 20", ["HealthValue"]="10", ["uuid"]="51c4226e-9bd0-4768-8336-60889fe24f5b", ["CurrentElectricityFlow"]="0.00", ["IsConnected"]="1", ["ccList"]="5e 72 86 85 59 5a 73 70 25 27 71 32 20", ["TargetStatus"]="1", ["DeviceName"]="NAS_WR01Z-1", ["CurrentElectricityQuantity"]="3860.00", ["supportsCrc"]="0", ["type"]="NAS_WR01Z", ["nodeFlags"]={}}, ["dev_2"]={["internalAddress"]="2", ["name"]="HAE_METER_v3", ["supportedCC"]="5e 86 72 32 56 5a 59 85 73 7a 60 8e 22 70 8b 3c 3d 3e", ["uuid"]="613a67ae-0412-45b3-9a1a-c147570fa19a", ["IsConnected"]="1", ["ccList"]="5e 86 72 32 56 5a 59 85 73 7a 60 8e 22 70 8b 3c 3d 3e", ["DeviceName"]="HAE_METER_v3", ["HealthValue"]="10", ["supportsCrc"]="1", ["type"]="HAE_METER_v3", ["nodeFlags"]={}}, ["dev_2.7"]={["internalAddress"]="2.7", ["name"]="HAE_METER_v3_7", ["supportedCC"]="5e 59 85 8e 3c 3d 3e", ["uuid"]="7400faa9-f92f-4fb5-b7f2-4ffde650469f", ["CurrentElectricityFlow"]="0.00", ["ccList"]="5e 59 85 8e 3c 3d 3e", ["DeviceName"]="HAE_METER_v3_7", ["CurrentElectricityQuantity"]="0.00", ["supportsCrc"]="0", ["type"]="HAE_METER_v3_7", ["nodeFlags"]={}}}
2018-11-04 09:30:00.468 Status: dzVents: Error (2.4.6): An error occured when calling event handler TOON
2018-11-04 09:30:00.471 Status: dzVents: Error (2.4.6): ...e/pi/domoticz/scripts/dzVents/generated_scripts/TOON.lua:57: attempt to index field 'dev_44' (a nil value)
2018-11-04 09:30:00.471 Status: dzVents: Info: ------ Finished TOON