Get Sun Power value

Moderator: leecollings

Post Reply
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Get Sun Power value

Post 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).
User avatar
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

Post 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.
Quality outlives Quantity!
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Get Sun Power value

Post by nitpicker »

I did try it with dzVents, but all what I tried, it doesn't work, only errors in the log.
willemd
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

Post 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)
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Get Sun Power value

Post 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
User avatar
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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
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

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

nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Get Sun Power value

Post 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 !
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Get Sun Power value

Post 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
 }
User avatar
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

Post 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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Get Sun Power value

Post 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)!
willemd
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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest