[Solved]Display a different Variable value at the Dashboard [not with Blockly] but with dzVents

Moderator: leecollings

McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

[Solved]Display a different Variable value at the Dashboard [not with Blockly] but with dzVents

Post by McJohn »

We have read a lot of Domoticz posts but we can’t find the solution with Blockly.
With the UV meter we have a blocky script that put the max UV Value of the day into a Variable.
That works.
But we want the value of that Max UV value into the Dashboard.
So, because it’s not possible to display a variable directly at the Dashboard with Domoticz, we made a Utility Text Device “UVMax today” and a blocky script to put the value of the UVMax Variable into that Utility Device. But that won’t work.
The result in the Util Device is “Variable[8]”

Is it not possible with Blockly to put a Variable value into a Text Device?

Thanks for the help and kind regards,

John
Attachments
Screen Shot 2019-04-28 at 16.49.45.png
Screen Shot 2019-04-28 at 16.49.45.png (53.94 KiB) Viewed 4555 times
Screen Shot 2019-04-28 at 16.45.32.png
Screen Shot 2019-04-28 at 16.45.32.png (83.59 KiB) Viewed 4555 times
Last edited by McJohn on Wednesday 01 May 2019 11:06, edited 3 times in total.
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

OK, if this is not possible with Blockly, has anyone an idea how to do this with another type of scripting?

Thanks in advance for the help.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

using dzVents it could look like

Code: Select all

return {
    on = {
             variables = {"maxUV today"} -- change to name of your Max UV uservariable
         },

    execute = function(dz,item)
        uvTextDevice = dz.devices("Max UV today") -- change to name of your text device
        uvTextDevice.updateText("max UV today: " .. item.value .. " at " .. dz.time.rawTime)
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thank you very much, that's working well! :D

Is it right that these kind of scripts like dzVents and LUA are checking every minute and Blockly only fires when something happened?
So, for the system load of the processor, Blocky is more friendly and is working sometimes 59 seconds faster?....
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Monday 29 April 2019 17:34 Is it right that these kind of scripts like dzVents and LUA are checking every minute and Blockly only fires when something happened?
So, for the system load of the processor, Blocky is more friendly and is working something 59 seconds faster?....
No, that is not the case.

[ Device, variable, security, scenes, ... ] based Lua scripts and blockly's are triggered when the [Device, ...] are updated (not necessarily changed).

For time triggered scripts and blockly's it is different. The event system triggers all time based scripts (and dzVents.lua) and blockly's once a minute. In Lua and blockly the logic in those scripts need to take care if the actions inside them need to be executed less frequent.

For dzVents scripts (which are in fact functions) dzVents.lua is taking care of which of them need to be executed when. dzVents.lua receives a table with the events that occurred from the domoticz event system and dispatch and execute the scripts accordingly based on the on = section of the dzVents scripts.
To optimize performance further, dzVents will receive all device, vars etc. information only once for all device- and timer scripts and not for every individual script. So if you have more than a couple scripts this will improve performance.

For ALL event triggered scripts the remark applies that only one can be active at any time. So if two scripts are to be triggered by a device or timer, the 2nd one has to wait until the first one finished. This is because the domoticz event system is single threaded.

Hope this clarifies.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thank you very much for your time and the clear, extensive, explanation!
We know much more now! :geek:
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Sorry to disturb you again but the script is not working well:

When I change manually the UV Variable in the Domoticz User Variable list, the script is working well to the Text device.
But when the Variable is changed by Domoticz self (a test with a temperature sensor), the change is not visible in the Text device.
What's going wrong here?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Monday 29 April 2019 21:25 When I change manually the UV Variable in the Domoticz User Variable list, the script is working well to the Text device.
But when the Variable is changed by Domoticz self (a test with a temperature sensor), the change is not visible in the Text device.
What's going wrong here?
When a domoticz Variable is updated by a Blockly or standard Lua it will not trigger an event; when updated by an API call or by dzVents it will.
In this case we can change the dzVents script to be triggered by UV device and update the variable and the text device using this dzVents script directly. So you would not need your Blockly for this.

Code: Select all

local uvDevice = 'UV sensor' -- change to name of your UV device
local uvTextDevice = 'UV text sensor' -- change to name of your text device
local uvVariable = 'UV var' -- change to name of your variable 

return {
            on = {
                     devices = { uvDevice }, 
                     timer = { 'at 00:03' },         -- time to reset variable and text device
                 },
            
    execute = function(dz, item)
        uvVariable =  dz.variables(uvVariable) 
        uvTextDevice = dz.devices(uvTextDevice)
        
        if item.isTimer then
            uvVariable.set(0)
            uvTextDevice.updateText('max UV today: 0 at ' .. dz.time.rawTime)
        elseif item.uv > uvVariable.value then  
            uvVariable.set(item.uv)
            uvTextDevice.updateText('max UV today: ' .. item.uv .. ' at ' .. dz.time.rawTime)
        end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thank you very much for your explanation and script. Very nice to have 1 script for all and not a separate Blockly script for the Max Value to Variable.

Yesterday I found an old Lua script at the forum with the code below.
Can you tell me why this script is working well with the results of a Blockly to Variable script? I have tested this and the updates to the Text device are perfect.
Thanks in advance.

Code: Select all

commandArray = {}
local localvar1 = 66
    commandArray['UpdateDevice'] = localvar1 .. '|0|' .. tostring(uservariables["TempBuitenMax"])
return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Tuesday 30 April 2019 8:10 Yesterday I found an old Lua script at the forum with the code below.
Can you tell me why this script is working well with the results of a Blockly to Variable script? I have tested this and the updates to the Text device are perfect.
I searched the forum for TempBuitenMax and all I found was this topic. So please share the topic where this was posted initially.
Without real investigation I would say this is a time based Lua script which does not need a variable event to trigger it.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

This one:

https://www.domoticz.com/forum/viewtopi ... 99#p113799

And then the last code at the page:

Code: Select all

commandArray = {}
local localvar1 = 175
    commandArray['UpdateDevice'] = localvar1 .. '|0|' .. tostring(uservariables["testvar"])
return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Tuesday 30 April 2019 9:29 this one
Thx for the link. If you look at the last sentence of Paul's posting (the one from Wednesday 28 December 2016 10:10) it states

save the script as a time based script.

The Lua script posted in this topic copies the content of that variable every minute and writes it to a (virtual) sensor, irrespective of whether the variable was updated during that last minute or not.
(See my previous post where I tried to explain difference between time trigger based- and [ Device, variable, security, scenes, httpResponses, ... ] trigger based Lua scripts and blockly's )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by besix »

Hello, waaren
I want to use your script for Set Point thermostat instead of UV sensor
How to modify it?

[codelocal uvDevice = 'UV sensor' -- change to name of your UV device
local uvTextDevice = 'UV text sensor' -- change to name of your text device
local uvVariable = 'UV var' -- change to name of your variable

return {
on = {
devices = { uvDevice },
timer = { 'at 00:03' }, -- time to reset variable and text device
},

execute = function(dz, item)
uvVariable = dz.variables(uvVariable)
uvTextDevice = dz.devices(uvTextDevice)

if item.isTimer then
uvVariable.set(0)
uvTextDevice.updateText('max UV today: 0 at ' .. dz.time.rawTime)
elseif item.uv > uvVariable.value then
uvVariable.set(item.uv)
uvTextDevice.updateText('max UV today: ' .. item.uv .. ' at ' .. dz.time.rawTime)
end
end
}][/code]
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thanks for your explanation. Your script is indeed a more cleaner solution (and with the time of the last update in the text sensor, perfect!)

The last UV script is working now. Thanks again.

But now we want also the max outside temperature in a text device.
So, we used your script, but we got an error.
See log below.
What's going wrong here?
Normally Blockly places only the outside temperature in the TempOutsideMax Variable.
I think this has something to do with the combined humanity info from the sensor?

Thanks for your help!



2019-04-30 13:54:23.324 (Z-Stick) Temp + Humidity (Temp/Luchtv. Buiten)
2019-04-30 13:54:23.395 Status: dzVents: Info: Handling events for: "Temp/Luchtv. Buiten", value: "14.6;100;3"
2019-04-30 13:54:23.395 Status: dzVents: Info: ------ Start internal script: TempBuitenTextDZVents: Device: "Temp/Luchtv. Buiten (Z-Stick)", Index: 59
2019-04-30 13:54:23.396 Status: dzVents: Error (2.4.6): An error occured when calling event handler TempBuitenTextDZVents
2019-04-30 13:54:23.396 Status: dzVents: Error (2.4.6): ...ipts/dzVents/generated_scripts/TempBuitenTextDZVents.lua:18: attempt to compare number with nil
2019-04-30 13:54:23.396 Status: dzVents: Info: ------ Finished TempBuitenTextDZVents
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Tuesday 30 April 2019 14:05 We want also the max outside temperature in a text device. We used your script, but we got an error.
You forgot to post the new script. So kind of hard to find what's wrong.
This one should do it for temperature (not tested)

Code: Select all

local temperatureDevice = 'Temperature sensor' -- change to name of your Temperature device
local temperatureTextDevice = 'Temperature text sensor' -- change to name of your text device
local temperatureVariable = 'Temperature var' -- change to name of your variable 

return {
            on = {
                     devices = { temperatureDevice }, 
                     timer = { 'at 00:03' },         -- time to reset variable and text device
                 },
            
    execute = function(dz, item)
        temperatureVariable =  dz.variables(temperatureVariable) 
        temperatureTextDevice = dz.devices(temperatureTextDevice)
        
        if item.isTimer then
            temperatureVariable.set(-55)
            temperatureTextDevice.updateText('max Temperature today: notset yet' .. dz.time.rawTime)
        elseif item.temperature > temperatureVariable.value then  
            temperatureVariable.set(item.temperature)
            temperatureTextDevice.updateText('max Temperature today: ' .. item.temperature .. ' at ' .. dz.time.rawTime)
        end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

besix wrote: Tuesday 30 April 2019 12:29 I want to use your script for Set Point thermostat instead of UV sensor. How to modify it?
Not tested and assuming you want to keep the max. setpoint of a day in a text sensor, it could look like

Code: Select all

local setpointDevice = 'Setpoint' -- change to name of your setpoint device
local setpointTextDevice = 'Setpoint text sensor' -- change to name of your text device
local setpointVariable = 'Setpoint var' -- change to name of your variable 

return {
            on = {
                     devices = { setpointDevice }, 
                     timer = { 'at 00:03' },         -- time to reset variable and text device
                 },
            
    execute = function(dz, item)
        setpointVariable =  dz.variables(setpointVariable) 
        setpointTextDevice = dz.devices(setpointTextDevice)
        
        if item.isTimer then
            setpointVariable.set(-55)
            setpointTextDevice.updateText('max setpoint today: notset yet' .. dz.time.rawTime)
        elseif item.setPoint > setpointVariable.value then  
            setpointVariable.set(item.setPoint)
            setpointTextDevice.updateText('max setpoint today: ' .. item.setPoint .. ' at ' .. dz.time.rawTime)
        end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thanks for the fast reply!
Your last Max Temp script is working!

But we have a little rounding problem:...
The temp sensor device says:
14.1 C

The result of your script into the Variable MaxTempOutside is:
14.199999809265. :o

And that result is also displaying into the the Text device.....


Below the result of the log:

2019-04-30 15:40:22.790 (Z-Stick) Temp + Humidity (Temp/Luchtv. Buiten)
2019-04-30 15:40:22.919 Status: dzVents: Info: Handling events for: "Temp/Luchtv. Buiten", value: "14.2;98;3"
2019-04-30 15:40:22.919 Status: dzVents: Info: ------ Start internal script: TempBuitenTextDZVents: Device: "Temp/Luchtv. Buiten (Z-Stick)", Index: 59
2019-04-30 15:40:22.920 Status: dzVents: Info: ------ Finished TempBuitenTextDZVents
2019-04-30 15:40:22.989 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-04-30 15:40:23.264 (Z-Stick) Temp + Humidity (Temp/Luchtv. Buiten)
2019-04-30 15:40:23.027 Status: Set UserVariable TempBuitenMax = 14.199999809265
2019-04-30 15:40:23.375 Status: dzVents: Info: Handling events for: "Temp/Luchtv. Buiten", value: "14.2;99;3"
2019-04-30 15:40:23.375 Status: dzVents: Info: ------ Start internal script: TempBuitenTextDZVents: Device: "Temp/Luchtv. Buiten (Z-Stick)", Index: 59
2019-04-30 15:40:23.376 Status: dzVents: Info: ------ Finished TempBuitenTextDZVents
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by waaren »

McJohn wrote: Tuesday 30 April 2019 15:39 But we have a little rounding problem:...
Please have look at the documentation first. A lot of the answers are already there

Change line 19/20 to

Code: Select all

            temperatureVariable.set(dz.utils.round(item.temperature,1))
            temperatureTextDevice.updateText('max Temperature today: ' .. dz.utils.round(item.temperature,1) .. ' at ' .. dz.time.rawTime)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by McJohn »

Thanks for the hint.
With Blocky the displayed temperature is exactly also copied to the Variable.
DzVents finds a lot more info... ;)

But the rounding is also working well now and this case is closed.
Thanks again for all your time and patience.
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: Display a different Variable value at the Dashboard with Blockly

Post by besix »

Thank you very much waaren for help, but I get an error in line 18
I just had it when I tried to modify it myself. Still important, I do not have to have the max only current
link to foto
https://prntscr.com/nir6sx

Sorry for my English
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest