GarbageCalendar (new version) lua scripts
Moderator: leecollings
-
- Posts: 204
- Joined: Monday 08 May 2017 20:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: Belgium
- Contact:
Re: GarbageCalendar (new version) lua scripts
@Reneb, Jos provided me a working (old) version of the script for Ophaalkalender (BE). It's working perfectly fine again. The problem was curl and an invalid certificate at https://www.ophaalkalender.be. I use the old script in the internal event editor on a Synology NAS.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
I have a working update which will use the internal Domoticz LUA when test for a external LUA version fails.jvdz wrote: ↑Friday 05 June 2020 21:28 So the original works because it is shelled by the internal Domoticz LUA interpreter and the WebUpdate module fails to shell because the requires the separate LUA interpreter?
We could make it fully run from within Domoticz as Option, but the downside is that the WebUpdate will be run by the Event system. (Like to old version).
Would that be an option?
Jos
This version is uploaded to the Development branch in github: https://github.com/jvanderzande/Garbage ... evelopment
Any one (@sammyke007 or @Reneb) willing to try this on a Synology NAS to see if that solves the reported issue?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
I am trying to get this working, but it does not seems to run:
The script path is set to /home/pi/domoticz/scripts/lua/
The file is updated. Not sure if required but did a chmod 755 on all the lua files.
I seem to miss something.
(And does Domoticz run the script every so often? In the installation guide I dont see how the script is triggered, but I have only used Dzvents so far.
Code: Select all
pi@raspberrypi:~/domoticz/scripts/lua $ lua script_time_garbagecalendar.lua
!!! Error opening runlogfile /var/tmp/garbagecalendar_run_m_mijnafvalwijzer.log
#### 12:20:01 start garbagecalendar script v20200606-1100
!!! failed loading "garbagecalendarconfig.lua" from : "/home/pi/domoticz/scripts/lua/garbagecalendar/"
Ensure you have copied "garbagecalendarconfig_model.lua" to "garbagecalendarconfig.lua" and modified it to your requirements.
Also check the path in variable "scriptpath= " is correctly set.
!!! LUA Error: script_time_garbagecalendar.lua:43: attempt to index global 'file' (a nil value)
pi@raspberrypi:~/domoticz/scripts/lua $ cd /home/pi/domoticz/scripts/lua/garbagecalendar/
pi@raspberrypi:~/domoticz/scripts/lua/garbagecalendar $ ls
garbagecalendarconfig.lua m_deafvalapp.lua m_montferland.lua m_opzet.lua m_zuidlimburg.lua
garbagecalendarconfig_model.lua m_goeree-overflakkee.lua m_ophaalkalender-be.lua m_westland.lua
generalfuncs.lua m_mijnafvalwijzer.lua m_opzet_api.lua m_ximmio.lua
The file is updated. Not sure if required but did a chmod 755 on all the lua files.
I seem to miss something.
(And does Domoticz run the script every so often? In the installation guide I dont see how the script is triggered, but I have only used Dzvents so far.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Does this directory "/var/tmp" exist in your installation and do you have the rights to create a file there?Hann1BaL wrote: ↑Wednesday 10 June 2020 12:24Code: Select all
!!! Error opening runlogfile /var/tmp/garbagecalendar_run_m_mijnafvalwijzer.log
Does this file exist in your setup and do you have access with this account? : "/home/pi/domoticz/scripts/lua/garbagecalendar/garbagecalendarconfig.lua"Hann1BaL wrote: ↑Wednesday 10 June 2020 12:24Code: Select all
!!! failed loading "garbagecalendarconfig.lua" from : "/home/pi/domoticz/scripts/lua/garbagecalendar/" Ensure you have copied "garbagecalendarconfig_model.lua" to "garbagecalendarconfig.lua" and modified it to your requirements. Also check the path in variable "scriptpath= " is correctly set.
When you follow the installation instructions, the file "script_time_garbagecalendar.lua" will be in the "/home/pi/domoticz/scripts/lua" directory, so by definition it will be ran each minute as it has the filename format for a time script.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
I have now chmod 777 on the log file, would that be enough?jvdz wrote: ↑Wednesday 10 June 2020 12:56Does this directory "/var/tmp" exist in your installation and do you have the rights to create a file there?Hann1BaL wrote: ↑Wednesday 10 June 2020 12:24Code: Select all
!!! Error opening runlogfile /var/tmp/garbagecalendar_run_m_mijnafvalwijzer.log
Does this file exist in your setup and do you have access with this account? : "/home/pi/domoticz/scripts/lua/garbagecalendar/garbagecalendarconfig.lua"Hann1BaL wrote: ↑Wednesday 10 June 2020 12:24Code: Select all
!!! failed loading "garbagecalendarconfig.lua" from : "/home/pi/domoticz/scripts/lua/garbagecalendar/" Ensure you have copied "garbagecalendarconfig_model.lua" to "garbagecalendarconfig.lua" and modified it to your requirements. Also check the path in variable "scriptpath= " is correctly set.
When you follow the installation instructions, the file "script_time_garbagecalendar.lua" will be in the "/home/pi/domoticz/scripts/lua" directory, so by definition it will be ran each minute as it has the filename format for a time script.
Jos
edit: actually:
Code: Select all
drwxrwxrwt 4 root root 4096 Jun 10 14:27 tmp
drwxr-xr-x 3 root root 4096 Apr 7 22:35 www
pi@raspberrypi:/var $
Then ran the script again manually:
Code: Select all
pi@raspberrypi:/var/tmp $ cat garbagecalendar_run_m_mijnafvalwijzer.log
@GarbageCal(m_mijnafvalwijzer): #### Wed Jun 10 14:02:00 2020 ### Start garbagecalendar script v20200606-1100
@GarbageCal(m_mijnafvalwijzer): domoticzjsonpath: /home/pi/domoticz/scripts/lua/
@GarbageCal(m_mijnafvalwijzer): datafilepath: /var/tmp/
@GarbageCal(m_mijnafvalwijzer): scriptpath: /home/pi/domoticz/scripts/lua/
@GarbageCal(m_mijnafvalwijzer): Loaded /home/pi/domoticz/scripts/lua/garbagecalendar/garbagecalendarconfig.lua.
@GarbageCal(m_mijnafvalwijzer): Loaded /home/pi/domoticz/scripts/lua/garbagecalendar/generalfuncs.lua.
@GarbageCal(m_mijnafvalwijzer): Start checking garbagetype_cfg table:
@GarbageCal(m_mijnafvalwijzer): -> NotificationTime:19:22 Garbagetype:pmd
@GarbageCal(m_mijnafvalwijzer): -> NotificationTime:2:30 Garbagetype:reloaddata
@GarbageCal(m_mijnafvalwijzer): -> NotificationTime:2:31 Garbagetype:dummy1
@GarbageCal(m_mijnafvalwijzer): -> NotificationTime:19:22 Garbagetype:papier
@GarbageCal(m_mijnafvalwijzer): -> NotificationTime:19:22 Garbagetype:gft
@GarbageCal(m_mijnafvalwijzer): Scheduled time(s) not reached yet, so nothing to do!
@GarbageCal(m_mijnafvalwijzer): #### 14:02:00 End garbagecalendar script v20200606-1100
@GarbageCal(m_mijnafvalwijzer): ==> found schedule:papier: vri 12 jun ; gft: maa 15 jun ; pmd: vri 26 jun ;
Virtual sensor has been updated!
Now I can work on notifications and the actual correct time.
Then the real work starts, maybe someone has an idea: I have an IKEA Tradfri color light which I want to switch on between 7.00am and 9.00am in the color of the bin on the specific bin day. Then when I walk in, I know to take the bin out and more importantly my direct manager (aka wife) knows when its bin day!
(Your response was quick, thanks very much Jos)
Cheers,
Tim
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Sweet
EDIT: The text device will only update at one of the defined times in the "garbagetype_cfg table". mydebug=true will force this each minute and give you the extensive logging.... so don't forget to change that back to "mydebug=false" when everything is running.
That is relative easy to do:Hann1BaL wrote: ↑Wednesday 10 June 2020 14:04 Then the real work starts, maybe someone has an idea: I have an IKEA Tradfri color light which I want to switch on between 7.00am and 9.00am in the color of the bin on the specific bin day. Then when I walk in, I know to take the bin out and more importantly my direct manager (aka wife) knows when its bin day!
At notification time, you run a script that will set a uservariable to the GarbageType by using option:
Code: Select all
Notificationscript = '' -- Specify personal notification script/command eg: lua sendmessage.lua
Then this same time script will switch the light off again at 9:00AM and reset the UserVariable to "".
You're welcome Tim.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
Thanks again!
I know I am asking a lot, but I am not a script master. I can build simple DzVents scripts to group devices and utilize dummy switches and change the state of things.
Do you have any example that would give some tools to start testing this?
How can I get the information required in a Dzvents script that I can match:
- color based on pmd, papier or gft
- match date
I know I have the information, but linking the 2 is where I don't see where to go right now.
(Again, I fully understand you deliver an awesome script to give notifications and virtual sensor to see garbage dates, which will save me runs to the garden and put the bin out when I see the garbage truck!)
I know I am asking a lot, but I am not a script master. I can build simple DzVents scripts to group devices and utilize dummy switches and change the state of things.
Do you have any example that would give some tools to start testing this?
How can I get the information required in a Dzvents script that I can match:
- color based on pmd, papier or gft
- match date
I know I have the information, but linking the 2 is where I don't see where to go right now.
(Again, I fully understand you deliver an awesome script to give notifications and virtual sensor to see garbage dates, which will save me runs to the garden and put the bin out when I see the garbage truck!)
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
I am not a Dzvents scripter as I have build all my script before the Dzvents era.
... but let me give you an example based on the above idea.
Steps to take to make this work:
1. Create a Domoticz UserVariable "GarbageCalendarNotify" als String.
2. Copy this script to the garbagecalendar directory in file "garbage_notification.lua":
Code: Select all
-- Update GarbageCalendarConfig.lua with:
-- Notificationscript = 'lua /home/pi/domoticz/scripts/lua/garbagecalendar/garbage_notification.lua "@GARBAGETYPE@" > /var/tmp/garbage_notification.log 2>&1 ' -- Specify personal notification script/command eg: lua sendmessage.lua
-----------------------------------------------------
-- script to set an UserVariable for GarbageCalendar
-----------------------------------------------------
-- url_decode function
function url_encode(str)
if (str) then
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
-- openurl function
function openurl(url)
print('curl "'..url..'"')
-- URL open with 2 seconds timeout
os.execute('curl -m 2 "'..url..'"')
end
-- ### main script
-- Variables
local baseurldomo = "http://127.0.0.1:8080"
local color = "?"
local sline=5 -- start line for text on OLED
local lines=2 -- max lines
local MaxLineLen=15 -- max line lenght on OLED
local GarbageType=arg[1] or "" -- Get first parameter which is the text to show on the OLED for GarbageCalender
--
print("GarbageType="..GarbageType)
if (GarbageType:lower() == "grijze bak") then -- ### Change this to the correct GarbageType!!
color = "grijs"
print("*** Overige")
elseif (GarbageType:lower() == "groene bak") then -- ### Change this to the correct GarbageType!!
color = "groen"
print("*** GFT")
elseif (GarbageType:lower() == "blauwe bak") then -- ### Change this to the correct GarbageType!!
color = "blauw"
print("*** Papier")
else
color = "rood"
print("*** onbekend afvaltype:" .. GarbageType:lower())
end
--- Set uservariable in domoticz to next current Garbage Type for collection
openurl( baseurldomo..'/json.htm?type=command¶m=updateuservariable&vname=GarbageCalendarNotify&vtype=2&vvalue='..color)
-- Set logrecord in domoticz log
openurl(baseurldomo..'/json.htm?type=command¶m=addlogmessage&message=' .. url_encode("GarbageNotification->"..color))
Code: Select all
Notificationscript = 'lua /home/pi/domoticz/scripts/lua/garbagecalendar/garbage_notification.lua "@GARBAGETYPE@"
Code: Select all
--[[
Script to set the Light to the correct color for the garbage
--]]
commandArray = {}
-- Switch the Light on a 0700 when uservariable GarbageCalendarNotify contains a color
if (os.date("%H%M")== "0700" and uservariables['GarbageCalendarNotify'] ~= "" ) then
if commandArray['Variable:GarbageCalendarNotify'] == "grijs" then
commandArray['YOurLight']= "to grijs"
elseif commandArray['Variable:GarbageCalendarNotify'] == "groen" then
commandArray['YOurLight']= "to groen"
elseif commandArray['Variable:GarbageCalendarNotify'] == "blauw" then
commandArray['YOurLight']= "to blauw"
else
commandArray['YOurLight']= "rood"
end
end
-- Switch light off at 0900 and reset UserVariable
if (os.date("%H%M")== "0900" and uservariables['GarbageCalendarNotify'] ~= "" ) then
commandArray['YourLight']= "Off"
commandArray['Variable:GarbageCalendarNotify'] = ""
end
return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
Awesome. Thanks for the homework
That provides me a great start to start testing different options and how it works out!
That provides me a great start to start testing different options and how it works out!
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
I have amended your script to the values that mijnafvalwijzer provides for us: gft, pmd and papierjvdz wrote: ↑Friday 12 June 2020 11:41I am not a Dzvents scripter as I have build all my script before the Dzvents era.
... but let me give you an example based on the above idea.
Steps to take to make this work:
1. Create a Domoticz UserVariable "GarbageCalendarNotify" als String.
2. Copy this script to the garbagecalendar directory in file "garbage_notification.lua":
-- Update GarbageCalendarConfig.lua with:The above is all "untested" so there might be some issues still in there but it is to get your started.Code: Select all
-- Notificationscript = 'lua /home/pi/domoticz/scripts/lua/garbagecalendar/garbage_notification.lua "@GARBAGETYPE@" >
Jos
and set the GarbageCalendarNotify to one of these values: "bruin", "oranje" or "blauw", the matching colours of the bin. At notification time the User variable gets updated.
Then I am using a Dzvents script that gets triggered when the User variable gets updated (even when the value itself does NOT change, which is great because sometimes the next bin day is the same bin as before.)
DzVents script that now switches a light on at the notification time for 60 minutes:
Code: Select all
return {
on = {
variables = {
'GarbageCalendarNotify'
}
},
execute = function(domoticz, variable)
-- set local light as the device you want to set the color for, in my case an IKEA Tradfri full color light bulb. Hue light should work as well.
local light = domoticz.devices(1252)
-- color setting: https://jonasjacek.github.io/colors/
-- 208 DarkOrange #ff8700 rgb(255,135,0)
-- 21 Blue1 #0000ff rgb(0,0,255)
-- 46 Green1 #00ff00 rgb(0,255,0)
if (variable.value == 'oranje') then
domoticz.log('Variable ' .. variable.name .. ' was changed to oranje', domoticz.LOG_INFO)
light.setRGB(255,135,0)
light.switchOff().afterMin(60)
elseif (variable.value == 'bruin') then
domoticz.log('Variable ' .. variable.name .. ' was changed to bruin', domoticz.LOG_INFO)
light.setRGB(0,255,0)
light.switchOff().afterMin(60)
elseif (variable.value == 'blauw') then
domoticz.log('Variable ' .. variable.name .. ' was changed to blauw', domoticz.LOG_INFO)
light.setRGB(0,0,255)
light.switchOff().afterMin(60)
else
domoticz.log('Variable ' .. variable.name .. ' was changed to UNKNOWN. Please check', domoticz.LOG_INFO)
end
-- code
end
}
Please note that for "bruin" I set the light to bright green as a brown light has still to be invented
Thanks again!
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
It is fine as long as it works for you.
Isn't this color sort of brown: (160, 95, 50)?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 23
- Joined: Sunday 11 March 2018 15:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Contact:
Re: GarbageCalendar (new version) lua scripts
Yeah, it is, but when you have a light it may appear a bit orange OR the brightness is too low to clearly see the light being switched ON and the idea is that you want clear distinct colours and that is a lot easier with Green, Blue and Orange.
Just happy that it works.
Your notification script really helped me! It was translating the information from the script to something that I could read for DzVents!
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Any other members that used "ophaalkalender.be" as that now seems to be migrated to recycleapp.be?
I currently have a test version available in case any of you have issues and can test this new module.
The new module will be published after it is confirmed it's working as expected.
Jos
I currently have a test version available in case any of you have issues and can test this new module.
The new module will be published after it is confirmed it's working as expected.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 204
- Joined: Monday 08 May 2017 20:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: Belgium
- Contact:
Re: GarbageCalendar (new version) lua scripts
Jos fixed the Belgian recycleapp.be. Ophaalkalender.be stopped working. Tnx a lot for fixing it so fast!
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Seems json.mijnafvalwijzer.nl doesn't allow our default calls anymore so made a new version of m_afvalwijzer available which does the "good old" web-scraping to get the data. It is available on github.
Let me know when there is a way to update the API version so we can use that again.
Jos
Let me know when there is a way to update the API version so we can use that again.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- HansieNL
- Posts: 957
- Joined: Monday 28 September 2015 15:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: GarbageCalendar (new version) lua scripts
Thanks for the quick fix.
I'm using Dashticz as dashboard. Because the garbage script is not fixed (yet) I'm using your script and use a text block to show the garbage dates. Only the dates are on one line. Looks ther's no break after the different lines. Where do I have to add a linebreak in the lua file to have a breakline?
I'm using Dashticz as dashboard. Because the garbage script is not fixed (yet) I'm using your script and use a text block to show the garbage dates. Only the dates are on one line. Looks ther's no break after the different lines. Where do I have to add a linebreak in the lua file to have a breakline?
Blah blah blah
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Not sure how that is implemented in Dashticz, but my script inserts a CRLF ("\r\n") between the collection lines, which is supported by the standard interface.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- HansieNL
- Posts: 957
- Joined: Monday 28 September 2015 15:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: GarbageCalendar (new version) lua scripts
Thanks for the explanation. I’ll check what’s happening with the Dashticz text block.
Blah blah blah
- Xenomes
- Posts: 379
- Joined: Tuesday 27 November 2018 19:05
- Target OS: Linux
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
Is there a way to add manually dates, if there is no on-line Garbage Calendar data available? Ours is only provided in pdf.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: GarbageCalendar (new version) lua scripts
It isn't currently available, but should be really simple as all you need to do is make you own module that will convert the data into the "garbagecalendar_m_yourmodule.data" somehow ones per year.
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Who is online
Users browsing this forum: No registered users and 1 guest