Page 1 of 1
Blockly is getting too large (any alternatives ?)
Posted: Thursday 04 November 2021 10:28
by MadMedic
Hi guys, (and girls ?)
I've got a blockly active that actually works fine.
Yet, to accommodate for all events it is getting too large.It's a blockly that triggers once every day (at 12 o'clock) to pick up the values of 5 plantwatering sensors and triggers an alert-output when the value of any of these sensors comes blow the value of 3% soilmoisture.
To be able to accommodate for all of these different variables of the 5 sensors the blockly is getting way to large for comfort.
The question:
Is there a way to put this in more easy blockly or( if need be) another kind of script, dzvents or such that keeps reading all the sensors and triggers when one of more of the 5 sensors exceeds the value. And does so to account for all the different outcomes possible in the right way to show them in the alert ? Because as times passes I keep adding variables that I did not account for. Appearantly there are A LOT of combinations the way I constructed it now.
There MUST be an easier way, but I don't see it.
Perhaps something along the way of: if one or more sensors exceeds the 3% treshold put those sensors in the alert ?
Here is the blockly in the first 3 files.. the remaining 3 parts in the next message. Yup, it IS large

and cant attach more the 3 files per msg.
See spoiler: (so I won't flood the forum with many large png's)
Any help and/or insights would be greatly appreciated.
- Spoiler: show

- part 1
- Blockly1.png (82.9 KiB) Viewed 1677 times

- part 2
- Blockly2.png (82.93 KiB) Viewed 1677 times

- part 3
- Blockly3.png (85.4 KiB) Viewed 1677 times
Re: Blockly is getting too large (any alternatives ?)
Posted: Thursday 04 November 2021 10:30
by MadMedic
Re: Blockly is getting too large (any alternatives ?)
Posted: Sunday 28 November 2021 14:21
by MadMedic
No one has any suggestions ?
How do I account for all of the five different sensorvariables, and not get an awfully large Blockly script
But at the same time get the right plantwateringtext in the text button.
So for instance:
plant 1, 3 and 5 need water
Re: Blockly is getting too large (any alternatives ?)
Posted: Sunday 28 November 2021 15:33
by EddyG
You might split it up into 5 blockies, 1 for every plant, or put everything in a dzVents script.
Re: Blockly is getting too large (any alternatives ?)
Posted: Tuesday 30 November 2021 23:12
by keros
It would be a lot easier if you move to a code script : while your checking your plant, you can generate your log message.
Message = ""
If plant1< 3 then Message = Message + "1"
If plant2< 3 then Message = Message + "2"
If plant3< 3 then Message = Message + "3"
If plant4< 3 then Message = Message + "4"
If plant5< 3 then Message = Message + "5"
If Message == "" then Log = "No need for plants"
Else Log = "Plants " + Message + " needs water"
Re: Blockly is getting too large (any alternatives ?)
Posted: Wednesday 01 December 2021 10:31
by boum
Yes, it would be easier in dzVents. I am not sure of the way to access the device value, but it could look like:
Code: Select all
local plantDevices = {
-- use ['name'] = 'deviceName', pairs. Currently numbers, but could be ['Cactus 1'] = 'Plant 17 Vochtigheid',
['1'] = 'Plant 1 Vochtigheid',
['2'] = 'Plant 2 Vochtigheid',
['3'] = 'Plant 3 Vochtigheid',
['4'] = 'Plant 4 Vochtigheid',
['5'] = 'Plant 5 Vochtigheid',
}
-- this depends on the device type
local needWater = function(domoticz, deviceName)
local device = domoticz.devices(deviceName)
return device.moisture <= 3
end
return {
on = {
timer = {
'at 11:57' -- avoid full hour when other processes might happen
}
},
execute = function(domoticz, item)
local need = {}
for name,deviceName in pairs(plantDevices) do
if needWater(domoticz, deviceName) then
table.insert(need, name)
end
end
local plantText = '' -- default message when no need to water
local count = #need
if count > 0 then
plantText = 'Plant'
for index,name in ipairs(need) do
if index == 1 then
plantText = plantText + ' '
elseif index == count then
plantText = plantText + ' en '
else
plantText = plantText + ', '
end
plantText = plantText + name
end
plantText = plantText + ' water nodig'
domoticz.log(plantText, domoticz.LOG_INFO)
end
local textDevice = domoticz.devices('Plantalert')
textDevice.updateText(plantText)
end
}
Not really tested, and the function needWater might need change (I based it from
https://www.domoticz.com/wiki/DzVents:_ ... l_moisture)
Re: Blockly is getting too large (any alternatives ?)
Posted: Sunday 05 December 2021 22:10
by MadMedic
Ok thanks for the effort, guys. With this I can work with
Re: Blockly is getting too large (any alternatives ?)
Posted: Tuesday 07 December 2021 20:23
by MadMedic
keros wrote: ↑Tuesday 30 November 2021 23:12
It would be a lot easier if you move to a code script : while your checking your plant, you can generate your log message.
Message = ""
If plant1< 3 then Message = Message + "1"
If plant2< 3 then Message = Message + "2"
If plant3< 3 then Message = Message + "3"
If plant4< 3 then Message = Message + "4"
If plant5< 3 then Message = Message + "5"
If Message == "" then Log = "No need for plants"
Else Log = "Plants " + Message + " needs water"
So, if for instance plants 1, 2, 3 and 5 needed water it would read:
Plant 1 needs water, Plant 2 needs water, Plant 3 needs water, Plant 5 needs water.
A bit long, don't you agree ?
I would prefer it showing that
Plant 1, 2, 3 and 5 need water to fit into one text column

Re: Blockly is getting too large (any alternatives ?)
Posted: Friday 10 December 2021 16:11
by keros
No, if for instance plants 1, 2, 3 and 5 needed water it would read: Plants 1235 needs water
Of course you can add spaces, change the texte if there is only one plant (singular).
Re: Blockly is getting too large (any alternatives ?)
Posted: Saturday 25 December 2021 16:57
by madpatrick
Hi,
i'm trying to use and rebuild this script for my doorsensors
What i try to achieve is a text in a dummy block with the status of which door is open.
I've rebuild it to this, but unfortunately no text or message
The problem looks to be in the table function
Code: Select all
local scriptVersion = 'Versie 1.00'
scriptVar = "-=# Deursensoren #=-"
local doorDevices = {
['Sensor1'] = 182, -- 'Sensor - Balkondeur',
['Sensor2'] = 188, -- 'Sensor - Garagedeur',
['Sensor3'] = 471, -- 'Sensor - Achterdeur',
['Sensor4'] = 474, -- 'Sensor - Erker',
}
local statusDoor = function(domoticz, deviceName)
local device = domoticz.devices(deviceName)
return device.state == 'Open'
end
return {
on = {
devices = {182,188,471,474,355
}
},
logging = {
level = domoticz.LOG_ERROR, -- change to domoticz.LOG_ERROR when all OK
marker = scriptVar
},
execute = function(domoticz, item)
domoticz.log('Deursensor script is geactiveerd .......................', domoticz.LOG_FORCE)
local need = {}
for name,deviceName in pairs(doorDevices) do
if statusDoor(domoticz, deviceName) then
table.insert(need, name)
end
end
local doorText = '' -- default message when nothing is Open
local count = #need
if count > 0 then
doorText = 'Door'
for index,name in ipairs(need) do
if index == 1 then
doorText = doorText + ' '
elseif index == count then
doorText = doorText + ' en '
else
doorText = doorText + ', '
end
doorText = doorText + name
end
doorText = doorText + ' Deur is Open'
domoticz.log(doorText, domoticz.LOG_INFO)
domoticz.log('SCRIPT TEST TEXT (1)', domoticz.LOG_INFO)
end
local textblock = domoticz.devices(477)
textblock.updateText(doorText)
domoticz.log(doorText, domoticz.LOG_INFO)
domoticz.log('SCRIPT TEST TEXT (2)', domoticz.LOG_INFO)
end
}
I'm getting this error:
Code: Select all
2021-12-26 15:49:58.713 Error: dzVents: Error: (3.1.7) -=# Deursensoren #=-: An error occurred when calling event handler Script #1
2021-12-26 15:49:58.714 Error: dzVents: Error: (3.1.7) -=# Deursensoren #=-: ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: attempt to add a 'string' with a 'string'