Page 1 of 1
Get Sun Power value
Posted: Wednesday 08 February 2023 14:09
by nitpicker
I want to use the Sun Power value/state from Buienradar. But how can I split it to only have the integer? So I can create a equation with > or < ?
Name: Sun Power
Value: 41.000
State: 0/41.000
I want only to use the 41 (in this case).
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 17:00
by gizmocuz
You can use dzVents for this. It does not matter if it is a floating point.
And in case of buienradar, it is always a whole number, nut 41.5 but 41 or 42
Or if you want to trigger a notification, use the notification button on the device, or use blockly.
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 18:09
by nitpicker
I did try it with dzVents, but all what I tried, it doesn't work, only errors in the log.
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 18:16
by willemd
What kind of error messages? Show your script, show your messages, otherwise it is impossible to assist.
In the script, a simple statement like this should work (replace 8 by the idx of your sun power device)
domoticz.log('sunpower = ' .. domoticz.devices(8).sensorValue , domoticz.LOG_INFO)
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 19:55
by nitpicker
Too bad I deleted every script that didn't work, but I tried somethings like:
Code: Select all
local sunp = dz.devices(20).sensorValue (this one alone)
local sunPower = tonumber(sunp) (or in combination of this one)
if (sunPower < 60) and (sunPower > 50)
some commands
end
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 20:22
by waltervl
This should work but sunp should already be a number.
Did you try with the log statements as willemd proposed? This will help a lot in understand what happens.
Else post a full script with triggers etc that should work according you and tell what is going wrong.
Re: Get Sun Power value
Posted: Wednesday 08 February 2023 20:26
by willemd
This should work:
Code: Select all
local idxSunpower=20
return {
on = {
devices = {
idxSunpower,
},
},
logging = {
level = domoticz.LOG_INFO,
marker = 'sunpower',
},
execute = function(domoticz, triggeredItem)
domoticz.log('sunpower = ' .. domoticz.devices(idxSunpower).sensorValue , domoticz.LOG_INFO)
end
}
Re: Get Sun Power value
Posted: Thursday 09 February 2023 10:32
by nitpicker
Thanks @willemd, this script works like a charm. I nicely get a value in the log now.
Code: Select all
Handling events for: "Sun Power", value: "123.000"
sunpower: ------ Start internal script: Test: Device: "Sun Power (Buienradar)", Index: 20
sunpower: sunpower = 123.0
sunpower: ------ Finished Test
Now I'm going to use this in my script, and let you know if this works. Thanks again @willemd, @waltervl, @gizmocuz !
Re: Get Sun Power value
Posted: Thursday 09 February 2023 17:15
by nitpicker
Too bad: local sunPower = domoticz.devices(idxSunpower).sensorValue
results in: An error occured when calling event handler Kamer verlichting aan
...ipts/dzVents/generated_scripts/Kamer verlichting aan.lua:23: attempt to index a nil value (global 'domoticz')
Code: Select all
return
{
on =
{
timer =
{
'every minute',
},
devices =
{
idxSunpower,
},
},
logging =
{
level = domoticz.LOG_INFO,
marker = 'sunpower',
},
execute = function(dz, item)
local idxSunpower=22
local sunPower = domoticz.devices(idxSunpower).sensorValue
local lampHoek = dz.devices(392) -- Lamp Hoek
domoticz.log('sunpower = ' .. domoticz.devices(idxSunpower).sensorValue , domoticz.LOG_INFO)
domoticz.log('sunpower = ' .. sunPower , domoticz.LOG_INFO)
if (sunPower < 60) and (sunPower > 50) and dz.time.matchesRule('at 14:00-22:00') then
lampHoek.dimTo(40)
end
end
}
Re: Get Sun Power value
Posted: Thursday 09 February 2023 18:46
by waltervl
Do not mix domoticz and dz in functions. So for example in your script
domoticz.log('sunpower =
Should be
dz.log('sunpower =
This because you used dz in line
execute = function(dz, item)
Re: Get Sun Power value
Posted: Thursday 09 February 2023 19:30
by nitpicker
I changed all
domoticz to
dz, still got the error. After I removed the:
Code: Select all
logging =
{
level = dz.LOG_INFO,
marker = 'sunpower',
},
the error was gone and can I use the function as it was intended.
Thanks (again)!
Re: Get Sun Power value
Posted: Thursday 09 February 2023 19:51
by willemd
The way I understand the documentation
https://www.domoticz.com/wiki/DzVents:_ ... h_Domoticz
is that whatever you rename "domoticz" to within the execute section of the script only applies to that section.