Update thermostat setpoint  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Tweak
Posts: 12
Joined: Monday 16 September 2019 10:45
Target OS: -
Domoticz version:
Contact:

Update thermostat setpoint

Post by Tweak »

Maybe this does not belong here.. but it is dzVents scripts.. I followed this manual: https://ehoco.nl/geroote-toon-bedienen-met-domoticz/

(sorry that is in dutch)

Everything works great except 1 thing, i tried to fix it but that is really a no go.. at some point it was even stuck in a loop.

The thermostat Toon has "scenes" normally its set on Thuis, this scene has temp 20C
When i click on scene Weg, it will change on Toon to 12C but the dzVents script is sending a command to Toon with change temp to 12C
So the scene on Toon changes to "Handmatig" it should not send a change to Toon if the temp is the same.

It looks like this is a known issue: https://www.domoticz.com/wiki/Toon there is a script and it says:

"This script updates the selector level, so it doesn't execute the command actions. This way when a user operates the Toon, it will not get a second command from the selector switch."

But i really dont know how i can fix the dzVents script with that example.. Can someone help me?
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update thermostat setpoint

Post by HansieNL »

I’m using 2 scripts which only sets the setpoint and scene. Program is disabled in Toon. If I change temperature/scene from Domoticz or Toon both will be updated.
toon_setpoint.lua:

Code: Select all

 return {
	logging = {
		-- level = domoticz.LOG_DEBUG, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log level
		level = domoticz.LOG_INFO,
		marker = "(Setpoint)"
			  },
	on = {
		devices = {
			'Thermostaat'
				  }
		 },

	execute = function(domoticz, device)
		domoticz.openURL(string.format('http://192.168.2.17/happ_thermstat?action=setSetpoint&Setpoint=%s', device.setPoint*100))
		domoticz.log('Setting Toon setpoint to '.. device.setPoint)

	end
}
toon_script.lua:

Code: Select all

 local scriptVar = '(Toon)'

return {
	logging = {
                -- level = domoticz.LOG_DEBUG, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log level
                level = domoticz.LOG_INFO,
                marker = scriptVar,
			  },

	on = {
            timer = { 'every minute'},
            httpResponses = { scriptVar },
         },

	execute = function(domoticz, item)
    
        local dz = domoticz
		
        if item.isTimer then
            local ToonIP		  = '192.168.2.17'
            local url =  'http://' ..  ToonIP .. '/happ_thermstat?action=getThermostatInfo'

            dz.openURL({ 
                            url = url,
                            callback = scriptVar,
                       })
            return
        end
        
        if item.ok then
            
            local ToonThermostat  = 'Thermostaat' -- Sensor showing current setpoint
            local ToonScenes	  = 'Toons' -- Sensor showing current program
            local ToonTemperature = 'Binnen' -- Sensor showing current room temperature

            local jsonThermostatInfo = dz.utils.fromJSON(item.data)
                     
            if jsonThermostatInfo == nil then
                return
            end
           
       -- dz.utils.dumpTable (jsonThermostatInfo) -- remove when script runs OK
       
    -- Update the current setpoint
            local currentSetpoint = tonumber(jsonThermostatInfo.currentSetpoint) / 100

    -- 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 current scene
            local currentActiveTemp = tonumber(jsonThermostatInfo.currentSetpoint) / 100
                if currentActiveTemp == 21 then currentActiveState = 40 -- Comfort
            elseif currentActiveTemp == 19 then currentActiveState = 30 -- Home
            elseif currentActiveTemp == 15 then currentActiveState = 20 -- Sleep
            elseif currentActiveTemp == 12 then currentActiveState = 10 -- Away
            else								currentActiveState = 50 -- Manual
            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

    -- Update the current temperature
            local currentTemperature = tonumber(jsonThermostatInfo.currentTemp) / 100
                  currentTemperature = tonumber(string.format("%.1f", currentTemperature))  -- 1 decimaal is voldoende

    -- 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
        else
        	domoticz.log('Problem retrieving data from Toon. ' ,dz.LOG_ERROR)
            dz.utils.dumpTable(item) 
        end
	end
}
Scene level action for Away (change other levels too according temperature)

Code: Select all

 http://192.168.2.17/happ_thermstat?action=setSetpoint&Setpoint=1200
Leave Scene level action for manual empty.
Last edited by HansieNL on Saturday 12 October 2019 3:01, edited 1 time in total.
Blah blah blah
Tweak
Posts: 12
Joined: Monday 16 September 2019 10:45
Target OS: -
Domoticz version:
Contact:

Re: Update thermostat setpoint

Post by Tweak »

I think the problem will be there to.. in the script i use this is happening:

I change the scene with a switch to "Weg"
This means the temp on the Toon will go to 12c
The script runs to get the info from toon and it receives the temp is set on 12c but the setpoint on the domoticz does not match (old temp is 20c)
So it should update the temp on the domoticz and not sending changes to Toon

Code: Select all

 -- 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
  
^ that will run this:

Code: Select all

return {
   on = {
      devices = {
         'ToonThermostat'
      }
   },
   execute = function(domoticz, device)
             print(device.setPoint*100)
             domoticz.openURL(string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', domoticz.variables('UV_ToonIP').value, device.setPoint*100))
    end
  
}
And that makes no sense it should change the temp locally and not sending it to Toon. I think it should be possible to just change the setpoint local but how i dunno..
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update thermostat setpoint

Post by HansieNL »

Because the Toon script runs once a minute it can take max a minute of updating the scene/setpoint.
My scripts update Toon/Domoticz if temperature changes somewhere.
Blah blah blah
Tweak
Posts: 12
Joined: Monday 16 September 2019 10:45
Target OS: -
Domoticz version:
Contact:

Re: Update thermostat setpoint

Post by Tweak »

I prefer using the scripts that is made in dzVents because it works fine except the temp thingy on domoticz.
Someone that is "good" in scripting with LUA/dzVents maybe knows a solution. When i click the switch to Away this URL is called:

http://192.168.1.x/happ_thermstat?actio ... ureState=3

Toon will switch to scene Away and temp will be set to 12c (as example)

But Domoticz does not know that Toon is now set on 12c.

So i want to know is it possible to change this "number"

Image

To something else without starting this:

Code: Select all

return {
   on = {
      devices = {
         'ToonThermostat'
      }
   },
   execute = function(domoticz, device)
             print(device.setPoint*100)
             domoticz.openURL(string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', domoticz.variables('UV_ToonIP').value, device.setPoint*100))
    end
  
}
If this is started: domoticz.openURL(string.format('http://%s/happ_thermstat?action=setSetpoint&Setpoint=%s', domoticz.variables('UV_ToonIP').value, device.setPoint*100))

The number on the dashboard (domoticz) will change to the correct one but also Toon receives a command and the scene will be switched to manual.

So im looking for something that can change the temp on the dashboard without sending info to Toon. Maybe something like:

Code: Select all

 -- 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)
             -- Silent change temp only on domoticz dashboard
                commandArray['UpdateDevice'] = otherdevices_idx[ToonThermostat]..'|1|'..currentSetpoint <- something like this??
        --     domoticz.devices(ToonThermostat).updateSetPoint(currentSetpoint).silent() Dont use this. will send command to Toon.
        end
        
Tweak
Posts: 12
Joined: Monday 16 September 2019 10:45
Target OS: -
Domoticz version:
Contact:

Re: Update thermostat setpoint

Post by Tweak »

Ehh, that makes sense! -> https://www.domoticz.com/wiki/DzVents:_ ... _scripting

Follow-up event triggers
Normally if you issue a command, Domoticz will immediately trigger follow-up events, and dzVents will automatically trigger defined event scripts. If you trigger a scene, all devices in that scene will issue a change event. If you have event triggers for these devices, they will be executed by dzVents. If you don't want this to happen, add .silent() to your commands (exception is updateSetPoint).

(exception is updateSetPoint)…

-> https://www.domoticz.com/forum/viewtopic.php?t=26662

blockSetPoint = { initial = false }, -- Bug in TimedCommands (silent() does not work in updateSetPoint

That sucks, so i really need to change to something else..
Tweak
Posts: 12
Joined: Monday 16 September 2019 10:45
Target OS: -
Domoticz version:
Contact:

Re: Update thermostat setpoint  [Solved]

Post by Tweak »

Sometimes the solution is very easy :') upgraded to beta version! seems Silent works now.. Problem solved!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest