script to check, it's not working

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

Moderator: leecollings

Post Reply
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

script to check, it's not working

Post by ssk17051980 »

on = {
devices = {
'81' -- Replace with the actual IDX of the switch
}
},
logging = {
level = domoticz.LOG_DEBUG, -- Can be changed to domoticz.LOG_INFO to reduce logging volume
},
execute = function(domoticz, device)
local sensorName = '200' -- Replace with the actual IDX of the water sensor
local areaInSquareMeters = 1 -- Replace with actual area in square meters

if device.state == 'On' then
local amountOfWater = 0.52615 * areaInSquareMeters -- Calculates the amount of water
domoticz.devices(sensorName).updateCustomSensor(amountOfWater) -- Updates the custom water sensor
domoticz.log('Amount of water added: ' .. amountOfWater .. ' L', domoticz.LOG_DEBUG)
end
end
}


can somebody to corect the script ?
thx
HvdW
Posts: 614
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: script to check, it's not working

Post by HvdW »

check this example

Code: Select all

return
{
    on =
    {
        devices = { 'Room switch'}
    },

    execute = function(domoticz, roomSwitch)
        if (roomSwitch.active and domoticz.devices('Living room').temperature > 18) then
        domoticz.devices('Another switch').switchOn()
        domoticz.notify('This rocks!',
                        'Turns out that it is getting warm here',
                        domoticz.PRIORITY_LOW)
        end

}
look where you place the braces
Bugs bug me.
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: script to check, it's not working

Post by waltervl »

I linked you to this script viewtopic.php?p=255592#p255592

Why did you not use that?
And if something is not working please indicate what is not working. But better use the script I linked to.
Make a dummy rain device (in the script named 'regenmeter').
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: script to check, it's not working

Post by ssk17051980 »

I created the virtual sensor with the name regenmeter. I replaced the tippingbucketrain name with Terrace in the script, this being the element that transmits the information.
still no response from the dummy

return
{
on =
{
devices =
{
"tippingbucketrain",
},
},

logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},

execute = function(dz, item)

local rainDevice = dz.devices("Regenmeter") -- Your (virtual) rain device
local rainSwitch = dz.devices("Terasa") -- Your (triggered by bucket full) switch
local rainmm = 2 -- find out what 1 bucket full means in terms of mm
local rainTotal = 0
local timeSlice = math.min( (rainDevice.lastUpdate.secondsAgo / 3600), 10) -- at least 1 bucket in 10 hours

local rainAmountHour = dz.utils.round((rainmm / timeSlice),1)

if item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: script to check, it's not working

Post by waltervl »

As indicated please put code into brackets.
You did not replace tippingbicketrain to Terasa everywhere in the script. So the script will not be triggered when Terasa is switched.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests