Get Sun Power value
Moderator: leecollings
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Get Sun Power value
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).
Name: Sun Power
Value: 41.000
State: 0/41.000
I want only to use the 41 (in this case).
- gizmocuz
- Posts: 2350
- Joined: Thursday 11 July 2013 18:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Top of the world
- Contact:
Re: Get Sun Power value
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.
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.
Quality outlives Quantity!
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: Get Sun Power value
I did try it with dzVents, but all what I tried, it doesn't work, only errors in the log.
-
- Posts: 621
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Get Sun Power value
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)
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)
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: Get Sun Power value
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
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Get Sun Power value
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.
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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 621
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Get Sun Power value
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
}
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: Get Sun Power value
Thanks @willemd, this script works like a charm. I nicely get a value in the log now.
Now I'm going to use this in my script, and let you know if this works. Thanks again @willemd, @waltervl, @gizmocuz !
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
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: Get Sun Power value
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')
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
}
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Get Sun Power value
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)
domoticz.log('sunpower =
Should be
dz.log('sunpower =
This because you used dz in line
execute = function(dz, item)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 69
- Joined: Tuesday 29 July 2014 10:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: Get Sun Power value
I changed all domoticz to dz, still got the error. After I removed the: the error was gone and can I use the function as it was intended.
Thanks (again)!
Code: Select all
logging =
{
level = dz.LOG_INFO,
marker = 'sunpower',
},
Thanks (again)!
-
- Posts: 621
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Get Sun Power value
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.
is that whatever you rename "domoticz" to within the execute section of the script only applies to that section.
Who is online
Users browsing this forum: No registered users and 1 guest