Controlling Toon [HACKED] from Domoticz

For heating/cooling related questions in Domoticz
michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Thursday 04 January 2018 12:29

Did you create under user variable UV_ToonTemperatureSensorName
The name must be correct without any space also check at the end, I had that issue.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Thursday 04 January 2018 19:47

michel30 wrote:
Thursday 04 January 2018 12:29
Did you create under user variable UV_ToonTemperatureSensorName
The name must be correct without any space also check at the end, I had that issue.
I changed the name to ToonTemperature in variable, name temp device and in the script.
Still the same problem, no triggering of the script.

edit:
If I replaced the line:
commandArray[3] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonTemperatureSensorName], currentTemperature)}
with:
commandArray['OpenURL'] = '192.168.1.159:8080/json.htm?type=command&param=udevice&idx='..otherdevices_idx[ToonTemperatureSensorName]..'&nvalue=0&svalue='..currentTemperature
then the script is triggered!

Why is it not working with the UpdateDevice line?

michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Sunday 14 January 2018 17:53

@glsf91

Strange what script are you using lua script?

I also notes an issue, I updated my toon to version 4.10.6 and now it does not show the analog meter in domoticz

When I check this site: http://IP_TOON/happ_pwrusage?action=GetCurrentUsage I see this:

Code: Select all

 {
result: "ok",
powerUsage: {
value: null,
dayCost: null,
avgValue: null
},
powerProduction: {
value: 0,
dayCost: 0,
avgValue: 93.67
},
gasUsage: {
value: null,
dayCost: null,
avgValue: null
}
}  
It is complete diffrent than 4.9.26 does somebody has 4.10.6 analog meter running in domoticz?

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Sunday 14 January 2018 17:59

michel30 wrote:
Sunday 14 January 2018 17:53
@glsf91

Strange what script are you using lua script?
Yes I use lua script.

script:

Code: Select all

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

commandArray = {}

    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
    ToonIP = uservariables['UV_ToonIP']
    DomoticzIP = uservariables['UV_DomoticzIP']

    json = assert(loadfile "/home/john/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()
    
    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
    
    -- 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)
        -- JBR next line is not triggering the device script. replaced with the url.
        --commandArray[3] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonTemperatureSensorName], currentTemperature)}
        commandArray['OpenURL'] = DomoticzIP..':8080/json.htm?type=command&param=udevice&idx='..otherdevices_idx[ToonTemperatureSensorName]..'&nvalue=0&svalue='..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 = 'Op ' ..currentSetpoint.. '°'
    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
	
--        
--

return commandArray

michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Sunday 14 January 2018 18:14

@glsf91

And you run it on a windows computer? If I see you scrip.

I used a raspberry PI and don't use LUA but dzVents

Code: Select all

 
 
 return {
	on = {
		timer = {
			'every minute'
		}
	},
	execute = function(domoticz)
        local ToonThermostatSensorName = domoticz.variables('UV_ToonThermostatSensorName').value -- Sensor showing current setpoint
        local ToonTemperatureSensorName = domoticz.variables('UV_ToonTemperatureSensorName').value -- Sensor showing current room temperature
        local ToonScenesSensorName  = domoticz.variables('UV_ToonScenesSensorName').value -- Sensor showing current program
        local ToonAutoProgramSensorName = domoticz.variables('UV_ToonAutoProgramSensorName').value -- Sensor showing current auto program status
        local ToonProgramInformationSensorName = domoticz.variables('UV_ToonProgramInformationSensorName').value -- Sensor showing displaying program information status
        local ToonIP = domoticz.variables('UV_ToonIP').value
        local DomoticzIP = domoticz.variables('UV_DomoticzIP').value
    
        -- Handle json
        --local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")()  -- For Windows
        -- local json = assert(loadfile "/home/maes/domoticz/scripts/lua/JSON.lua")()  -- For Linux
         json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Raspberry
        
         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 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
        local currentNextTime = jsonThermostatInfo.nextTime
        local currentNextSetPoint = tonumber(jsonThermostatInfo.nextSetpoint) / 100
        local currentBoiletSetPoint = jsonThermostatInfo.currentInternalBoilerSetpoint
        ----
        
        -- Update the thermostat sensor to current setpoint
        if domoticz.devices(ToonThermostatSensorName).setPoint*100 ~= currentSetpoint*100 then
            domoticz.log('Updating thermostat sensor to new set point: ' ..currentSetpoint)
            domoticz.devices(ToonThermostatSensorName).updateSetPoint(currentSetpoint).silent()
        end
        

        -- Update the temperature sensor to current room temperature
        if domoticz.round(domoticz.devices(ToonTemperatureSensorName).temperature, 1) ~= domoticz.round(currentTemperature, 1) then 
            domoticz.log('Updating the temperature sensor to new value: ' ..currentTemperature)
            domoticz.devices(ToonTemperatureSensorName).updateTemperature(currentTemperature)
        end
        
        -- Update the toon scene selector sensor to current program state
        if domoticz.devices(ToonScenesSensorName).level ~= currentActiveState then  -- Update toon selector if it has changed
            domoticz.log('Updating Toon Scenes selector to: '..currentActiveState)
            domoticz.devices(ToonScenesSensorName).switchSelector(currentActiveState).silent()
        end
        
        -- Updates the toon auto program switch 
        if domoticz.devices(ToonAutoProgramSensorName).level ~= currentProgramState then -- Update toon auto program selector if it has changed
            domoticz.log('Updating Toon Auto Program selector to: '..currentProgramState)
            domoticz.devices(ToonAutoProgramSensorName).switchSelector(currentProgramState).silent()
        end
        
        -- Updates the toon program information text box
        if currentNextTime == 0 or currentNextSetPoint == 0 then
            ToonProgramInformationSensorValue = 'Op ' ..currentSetpoint.. '°'
        else
            ToonProgramInformationSensorValue = 'Om ' ..os.date('%H:%M', currentNextTime).. ' op ' ..currentNextSetPoint.. '°'
        end
        
        if domoticz.devices(ToonProgramInformationSensorName).text ~= ToonProgramInformationSensorValue then
            domoticz.log('Updating Toon Program Information to: '..ToonProgramInformationSensorValue)
            domoticz.devices(ToonProgramInformationSensorName).updateText(ToonProgramInformationSensorValue)
        end
	end
}
 
   

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Sunday 14 January 2018 18:26

michel30 wrote:
Sunday 14 January 2018 18:14
@glsf91

And you run it on a windows computer? If I see you scrip.

I used a raspberry PI and don't use LUA but dzVents
No, it is running on Ubuntu. Comment was old.

michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Sunday 14 January 2018 22:51

This line is wrong in your scrip:

json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")() -- For Windows

You need to change it to Ubuntu, see my scrip this one is change to raspberry pi.

Now it could not run on your ubuntu server.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Monday 15 January 2018 17:14

michel30 wrote:
Sunday 14 January 2018 22:51
This line is wrong in your scrip:

json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")() -- For Windows

You need to change it to Ubuntu, see my scrip this one is change to raspberry pi.

Now it could not run on your ubuntu server.
What do I have to change to this line?

john@ubuntu1:~$ ls -l /home/john/domoticz/scripts/lua/JSON.lua
-rw-rw-r-- 1 john john 50533 Nov 28 08:34 /home/john/domoticz/scripts/lua/JSON.lua

the path looks fine to me.

And the script is working. Only it don't triggers other scripts when listing for a Toon device.

michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Monday 15 January 2018 22:40

Hello,

Not there see your script that you post above on this site.
If you open it you see everything in "or check in domoticz"

In there you will see the path someting like this:


-- Handle json
--local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
--local json = assert(loadfile "/home/maes/domoticz/scripts/lua/JSON.lua")() -- For Linux
local json = assert(loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")() -- For Synology

Is see in you scrip use windows local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows

You need to change it for ubuntu someting like this: local json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")() -- For Linux

Otherwise it will not function.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Monday 15 January 2018 23:14

michel30 wrote:
Monday 15 January 2018 22:40
Hello,

Not there see your script that you post above on this site.
If you open it you see everything in "or check in domoticz"

In there you will see the path someting like this:


-- Handle json
--local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
--local json = assert(loadfile "/home/maes/domoticz/scripts/lua/JSON.lua")() -- For Linux
local json = assert(loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")() -- For Synology

Is see in you scrip use windows local json = assert(loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows

You need to change it for ubuntu someting like this: local json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")() -- For Linux

Otherwise it will not function.

My script is in a few posts above (Sunday 14 January 2018 16:59 ). In the script there is de line:
json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")() -- For Windows

The comment is wrong. That was a left over.
I also already added local in front of the line.
So I use: local json = assert(loadfile "/home/john/domoticz/scripts/lua/JSON.lua")()

User avatar
gijsje
Posts: 152
Joined: Saturday 19 August 2017 14:28
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: Berkel Enschot, NL
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by gijsje » Saturday 20 January 2018 20:56

I have added the boiler temp to the lue and it works for me

Code: Select all

-- 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
-- Udates Toon Burner status in order to see in domoticz if tyou boiler is on for the hotwater or heating or off (still is a undefined number which i must hunt down)
-- Updates Toon Boiler temp (gijsje)
commandArray = {}

    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 
    ToonIP = uservariables['UV_ToonIP']
    DomoticzIP = uservariables['UV_DomoticzIP']

    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()

-- 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
    currentProgramState = tonumber(jsonThermostatInfo.programState)
    currentActiveState = tonumber(jsonThermostatInfo.activeState)
    currentNextTime = jsonThermostatInfo.nextTime
	currentBurnerInfo = tonumber(jsonThermostatInfo.burnerInfo)
    currentNextSetPoint = tonumber(jsonThermostatInfo.nextSetpoint) / 100
	currentBoilerSetPoint = tonumber(jsonThermostatInfo.currentInternalBoilerSetpoint)
    
    -- 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 temperature of boiler
    if otherdevices_svalues[ToonBoilerTempSetpoint]*100 ~= currentBoilerSetPoint*100 then 
        print('Updating the boiler temperature to new value: ' ..currentBoilerSetPoint)
        commandArray[3] = {['UpdateDevice'] = string.format('%s|0|%s', otherdevices_idx[ToonBoilerTempSetpoint], currentBoilerSetPoint)}
    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 = 'Op ' ..currentSetpoint.. 'C'
    else
        ToonProgramInformationSensorValue = 'Om ' ..os.date('%H:%M', currentNextTime).. ' op ' ..currentNextSetPoint.. 'C'
    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
	
--

return commandArray
Synology DS218+ - RFXtrx433 - Aeotec Z-Stick Gen5 - Toon Thermostat - Neo CoolCam plug - Neo CoolCam PIR - FIBARO PIR - Heiman Smart Smoke Senso - Neo CoolCam Leakage Detector - BeNext Tag Reader - P1 and S0 USB - many Mi-Light lights - KAKU switches

User avatar
madpatrick
Posts: 49
Joined: Monday 26 December 2016 13:17
Target OS: Linux
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by madpatrick » Sunday 21 January 2018 19:43

Hi,

I've setup my domoticz server according the intial post, but for some reason the are still some issues.
1. When i use the LUA script "ToonGetInfo" and i change the Scene the selected scene will light up, but after a few second it dims and no scene is selected any more. The Scenes is set to "Manual" is Domoticz dashboard

2. When i want tp change "Toon Thermostat" temperature (using the LUA scripts), Domoticz hangs for a while and the temperature is not changed

3. When i use the DzVents script "ToonGetInfo", the scenes will not be update in Domoticz. The temperature setting is updated with the scene temperature.
The log file gives the following error

Code: Select all

2018-01-21 18:38:00.375 dzVents: Info: ------ Start internal script: ToonGetInfo:, trigger: every minute
2018-01-21 18:38:00.410 dzVents: Debug: Device-adapter found for Toon Thermostat: Thermostat setpoint device adapter
2018-01-21 18:38:00.411 dzVents: Debug: Processing device-adapter for Toon Thermostat: Thermostat setpoint device adapter
2018-01-21 18:38:00.412 dzVents: Debug: Device-adapter found for Toon Temperature: Temperature device adapter
2018-01-21 18:38:00.412 dzVents: Debug: Processing device-adapter for Toon Temperature: Temperature device adapter
2018-01-21 18:38:00.412 Error: dzVents: Error: An error occured when calling event handler ToonGetInfo
2018-01-21 18:38:00.412 Error: dzVents: Error: ...moticz/scripts/dzVents/generated_scripts/ToonGetInfo.lua:57: attempt to call field 'round' (a nil value)
2018-01-21 18:38:00.412 dzVents: Info: ------ Finished ToonGetInfo
ClearOS 7.5.0 - Toon 4.15.16 (rooted) - Domoticz 4.9700

User avatar
gielie
Posts: 221
Joined: Tuesday 12 January 2016 12:40
Target OS: Raspberry Pi
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by gielie » Thursday 25 January 2018 12:13

Im using the Toon script in combination with my hacked Toon and it works great, but.
Im looking for a way to set my selector switch "Toon auto program" from temporary to yes after a fixed time.

So when i put my thermostat at 21 degrees, the "Toon auto program" goes to "temporary" and i want it to go back to "Yes" (following the program) after 30 minutes. I tried this with a lua and with blocky but i cant get it to work.

Someone here can help me with that?
- Vision ZU1401 USB Stick
- Aeotec MultiSensor 6
- FIBARO FGS222
- FIBARO FGWPE Wall Plug
- Everspring AN157
- Neo CoolCam Power plug
- Neo CoolCam PIR Sensor
- Popp Smoke Detector
- Toon
- Kodi Media Server

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Saturday 27 January 2018 13:17

FunFair wrote:
Monday 13 November 2017 13:30

Try the script attached as a file. I've replaced dev_3.3 to dev_3.2 and removed the adding of the 2 tariffs.
If you don't have a smart meter I don't know if it's possible to differentiate between low and normal tariff. Toon does not store these values seperately to my knowledge.

The gas readout script does not have to be altered.
I used this script for analog electricity. For some reason the counter at Toon started from zero again. This will also happen when the meter adapter is plugged out and in again as far as I know. Maybe also when restarting Toon.
Then this script won't update Domoticz anymore because the value at Domoticz is higher then Toon: "Toon value incorrect, do nothing".

Does somebody have a solution for this?

Otelikse
Posts: 1
Joined: Tuesday 23 January 2018 20:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by Otelikse » Wednesday 31 January 2018 22:59

Dear all,

I am a complete newby with Domoticz. I am using a raspberry pi3 with domoticz. I have set all my lightning controls. At this moment like all of you bought a rooted Toon and trying to hook it up in domoticz. I am not the best programmer and therefor I am asking if anyone can help with it. I have read all but still do not understand how to do it.

FunFair
Posts: 37
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by FunFair » Friday 02 February 2018 22:26

glsf91 wrote:
Saturday 27 January 2018 13:17
FunFair wrote:
Monday 13 November 2017 13:30

Try the script attached as a file. I've replaced dev_3.3 to dev_3.2 and removed the adding of the 2 tariffs.
If you don't have a smart meter I don't know if it's possible to differentiate between low and normal tariff. Toon does not store these values seperately to my knowledge.

The gas readout script does not have to be altered.
I used this script for analog electricity. For some reason the counter at Toon started from zero again. This will also happen when the meter adapter is plugged out and in again as far as I know. Maybe also when restarting Toon.
Then this script won't update Domoticz anymore because the value at Domoticz is higher then Toon: "Toon value incorrect, do nothing".

Does somebody have a solution for this?
At the end of the script, remove the comparisment that checks if the values are different.
For a slimme meter I had to implement this because after a restart of toon the values would mess up as it wont update the low tariff during the day.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Sunday 04 February 2018 21:08

FunFair wrote:
Friday 02 February 2018 22:26

At the end of the script, remove the comparisment that checks if the values are different.
For a slimme meter I had to implement this because after a restart of toon the values would mess up as it wont update the low tariff during the day.
Then indeed Domoticz is getting data again. But because the counter starts at 0 again there is a big electricity consumption in the graphics of Domoticz.
Maybe it is better to use RRD data because it is not reset to 0.
Example:
http://192.168.1.234/hcb_rrd?action=get ... 18%2014:00

Code: Select all

{
"04-02-2018 15:00:00": 44476,
"04-02-2018 16:00:00": 45108,
"04-02-2018 17:00:00": 45765,
"04-02-2018 18:00:00": 46395,
"04-02-2018 19:00:00": 46988,
"04-02-2018 20:00:00": 47535,
"04-02-2018 21:00:00": 47585
}
I restarted between 19:00 and 20:00.
The last value is changed every x time until 21:00 is reached.

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by glsf91 » Tuesday 06 February 2018 22:14

I have changed/made a PHP script which reads now the analog gas counter from RRD instead of CurrentGasQuantity from getDevices.json. This last one is reset to zero after reboot of Toon (and I think also after restarting the meter adapter).

The counter in RDD is alway increasing, so no strange high measurements in Domoticz after rebooting Toon. Only the first day is showing a high value now when you start using this, because of the current high value in RRD. That cannot be avoided as far as I know (unless resetting Toon).
I'am not a php developer so probably things can be done smarter. But it looks like it is working.
It is derived from analog_electricity_data_json.php, earlier in this thread.

Code: Select all

#!/usr/bin/php
<?php

error_reporting(E_ALL);

/* Written by Ierlandfan */

/* modified by glsf91 */
/* 5-2-2018 */
/* Version 3.0 */

/* Set IP addresses and idx*/
$IPDomoticz = '192.168.1.159:8080'; #use 'username:password@domoticz-ip:port' in case of password protection.
$IPToon = '192.168.1.234';
$idx = 77;

/* read gas value from Domoticz */
$json_string = file_get_contents("http://$IPDomoticz/json.htm?type=devices&rid=$idx");
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
$GasCounterDomoticz = $parsed_json['Data']*1000;
echo "Gas Counter Domoticz = ";
echo $GasCounterDomoticz;
echo " liter";
echo "\n";

// Get current date
$datum =  date("d-m-Y");
echo "Request for FROM date: " . $datum . "\n";

// Get Gas counter from Toon
$file_string_gas = file_get_contents("http://$IPToon/hcb_rrd?action=getRrdData&loggerName=gas_quantity&rra=5yrhours&readableTime=1&nullForNaN=1&from=$datum" );
$parsed_json = json_decode($file_string_gas, true);
//var_dump($parsed_json);

if ( empty($parsed_json)) {
        echo "Array is empty. Stop executing\n";
        return;
}

// Get last value of array
$keys = array_keys($parsed_json);
end($parsed_json);
$key = key($parsed_json);
//var_dump($key);
$GasCounterToon = $parsed_json[$key];
echo "Gas counter from Toon = " . $GasCounterToon . " liter";
echo "\n";

/* write new value to Domoticz */
if ($GasCounterDomoticz == 0){ #this is for the first run only, when the idx is still empty.
        $WriteInitValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$GasCounterToon");
        curl_exec($WriteInitValue);
        }
        else if ($GasCounterToon < $GasCounterDomoticz){
                echo "Toon value incorrect, do nothing \n";
        }
        else if ($GasCounterToon >= $GasCounterDomoticz){
                $WriteValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$GasCounterToon");
                echo "\n";
                echo "Write new value \n";
                curl_exec($WriteValue);
        }
        else {
                echo "Domoticz value incorrect, do nothing \n";
        }


?>

Just like the earlier one, put this in cron for running every 1 minute:
*/1 * * * * /home/<directory>/domoticz/scripts/php/gas_data_rrd_json.php
Adjust path to the script.

I don't know if it also will work for a P1 gas meter instead of analog gas meter.

I have also changed the analog electricity to using RRD:

Code: Select all

#!/usr/bin/php
<?php

error_reporting(E_ALL);

/* Version 1.0 written by Ierlandfan */
/* Version 1.0 modified by DennisD */
/* Version 2.0 rewritten by FunFair */

/* Modified by glsf91 for using RRD */
/* 5-2-2018 */
/* Version 3.0 */

/* Set IP addresses and idx*/
$IPDomoticz = '192.168.1.159:8080'; #use 'username:password@domoticz-ip:port' in case of password protection.
$IPToon = '192.168.1.234';
$idx = 78;

/* read electricity value from Domoticz */
$json_string = file_get_contents("http://$IPDomoticz/json.htm?type=devices&rid=$idx");
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
$ElecCounterDomoticz = $parsed_json['Data']*1000;
echo "Electricity Counter Domoticz = ";
echo $ElecCounterDomoticz;
echo " Wh";
echo "\n";

/* start of current Energy usage import */
$file_string_ElecUsage = file_get_contents("http://$IPToon/happ_pwrusage?action=GetCurrentUsage");
$parsed_json_ElecUsage = json_decode($file_string_ElecUsage, true);

/* extract the current powerusage */
$ElecUsageToon=$parsed_json_ElecUsage['powerUsage']['value'];
echo "Electricity Usage Toon = ";
echo $ElecUsageToon;
echo " Watt";
echo "\n";


// Get current date
$datum =  date("d-m-Y");
echo "Request for FROM date: " . $datum . "\n";
//$datum = "07-02-2018";
//echo "Now: ". date("Y-m-d H:i:s") . "\n";

// Get Electricity LT counter from Toon
$file_string_electLT = file_get_contents("http://$IPToon/hcb_rrd?action=getRrdData&loggerName=elec_quantity_lt&rra=5yrhours&readableTime=1&nullForNaN=1&from=$datum" );
$parsed_json = json_decode($file_string_electLT, true);
//var_dump($parsed_json);

if ( empty($parsed_json)) {
        echo "Array is empty. Stop executing\n";
        return;
}

// Get last value of array
$keys = array_keys($parsed_json);
end($parsed_json);
$key = key($parsed_json);
//var_dump($key);
$ElecLTCounterToon = $parsed_json[$key];
echo "Electricity LT counter from Toon = " . $ElecLTCounterToon . " Wh";
echo "\n";

// Get Electricity NT counter from Toon
$file_string_electNT = file_get_contents("http://$IPToon/hcb_rrd?action=getRrdData&loggerName=elec_quantity_nt&rra=5yrhours&readableTime=1&nullForNaN=1&from=$datum" );
$parsed_json = json_decode($file_string_electNT, true);
//var_dump($parsed_json);

if ( empty($parsed_json)) {
        echo "Array is empty. Stop executing\n";
        return;
}

// Get last value of array
$keys = array_keys($parsed_json);
end($parsed_json);
$key = key($parsed_json);
//var_dump($key);
$ElecNTCounterToon = $parsed_json[$key];
echo "Electricity NT counter from Toon = " . $ElecNTCounterToon . " Wh";
echo "\n";

$ElecCounterToon = $ElecNTCounterToon + $ElecLTCounterToon;
echo "Electricity LT + NT counter from Toon = " . $ElecCounterToon . " Wh";
echo "\n";



/* write new value to Domoticz */
if ($ElecCounterDomoticz == 0){ #this is for the first run only, when the idx is still empty.
        $WriteInitValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$ElecUsageToon;$ElecCounterToon");
        curl_exec($WriteInitValue);
        }
        else if ($ElecCounterToon < $ElecCounterDomoticz){
                echo "Toon value incorrect, do nothing \n";
        }
        else if ($ElecCounterToon >= $ElecCounterDomoticz){
                $WriteValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$ElecUsageToon;$ElecCounterToon");
                echo "\n";
                echo "Write new value \n";
                curl_exec($WriteValue);
        }
        else {
                echo "Domoticz value incorrect, do nothing \n";
        }


?>
Add this one to the cron the same way.

michel30
Posts: 20
Joined: Tuesday 12 December 2017 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by michel30 » Thursday 08 February 2018 21:16

Hello,

I use the analog scrip for GAS and POWER, that works super in my domoticz.

Now I want to add the price and I see under the tap setup > settings > Meters/Counters the following fields: RFXMeter/Counter Dividers:

I edit the price in here, but I don't see it in my Domoticz I only see the GAS or power use.

How can I see the price in domoticz? or will this only works if you have a P1 cable?

FunFair
Posts: 37
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Controlling Toon [HACKED] from Domoticz

Post by FunFair » Monday 05 March 2018 20:04

glsf91 wrote:
Tuesday 06 February 2018 22:14
I have changed/made a PHP script which reads now the analog gas counter from RRD instead of CurrentGasQuantity from getDevices.json. This last one is reset to zero after reboot of Toon (and I think also after restarting the meter adapter).

The counter in RDD is alway increasing, so no strange high measurements in Domoticz after rebooting Toon. Only the first day is showing a high value now when you start using this, because of the current high value in RRD. That cannot be avoided as far as I know (unless resetting Toon).
I'am not a php developer so probably things can be done smarter. But it looks like it is working.
It is derived from analog_electricity_data_json.php, earlier in this thread.
Wow thanks! This is a much better solution than the previous one!!!!
It doesn't matter anymore if you have an analog or smart meter, as Toon writes the values in the same database.
I've used your code to clean up my versions and removed the comparisment incase Toon reported 'zero' values.

Tested these scripts with Toon version 4.9 and they work with:
- P1 Smart meter (including solar return)
- Analog/Digital Electricity meter
- Analog/Digital Gas meter

See file attached for who's interested.
Attachments
toon_scripts_version_3.zip
(4.41 KiB) Downloaded 77 times

Post Reply

Who is online

Users browsing this forum: Maes and 3 guests