Page 2 of 3
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 10:13
by waltervl
If you replace that by the line below it should do the trick.
Code: Select all
dz.openURL('https://api.telegram.org/botXXX:XXXX/sendMessage?chat_id=XXXXX&text=' .. message)
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 11:31
by Xavier82
When using the code
Code: Select all
dz.openURL('https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=' .. message)
I get this status:
Code: Select all
2023-01-05 13:41:00.634 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: url = https://api.telegram.org/botXXX:XXXXX/sendMessage?chat_id=XXXXXX&text=Mijn Energie Overzicht : 05-01-2023
2023-01-05 13:41:00.634 --------------P1 Elektriciteitmeter-----------
2023-01-05 13:41:00.634 Stroomkosten Totaal : € 3.23
2023-01-05 13:41:00.634 Stroomkosten Hoog : € 1.42
2023-01-05 13:41:00.634 Stroomkosten Laag : € 0.87
2023-01-05 13:41:00.634 Teruglevering Hoog : € 0.0
2023-01-05 13:41:00.634 Teruglevering Laag : € 0.0
2023-01-05 13:41:00.634 ---------------------------------------------------
2023-01-05 13:41:00.634 Verbruik Hoog : 3.538 kWh
2023-01-05 13:41:00.634 Verbruik Laag : 2.172 kWh
2023-01-05 13:41:00.634 Teruglevering Hoog : 0.0 kWh
2023-01-05 13:41:00.634 Teruglevering Laag : 0.0 kWh
2023-01-05 13:41:00.634 Totaal Verbruik Elektra vandaag : 5.718 kWh
2023-01-05 13:41:00.634 --------------P1 Gasmeter---------------------
2023-01-05 13:41:00.634 Gas M3 : € 0.84
2023-01-05 13:41:00.634 Totaal Verbruik Gas vandaag : 0.082 M3
2023-01-05 13:41:00.634 --------------Zonnepanelen--------------------
2023-01-05 13:41:00.634 Totaal Opbrengst Zonnepanelen : 0.0 kWh
2023-01-05 13:41:00.634 Zonopbrengst Totaal € 0.0
2023-01-05 13:41:00.634 -------------- Einde Dag Overzicht -------------
2023-01-05 13:41:00.634 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: method = GET
2023-01-05 13:41:00.634 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: post data = nil
2023-01-05 13:41:00.635 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: headers = nil
2023-01-05 13:41:00.635 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: callback = nil
2023-01-05 13:41:00.635 Status: dzVents: Info: Dag verbruik in euros 03/01/2023-/-v1.13: ------ Finished Dag verbruik in euros
and I get this error:
Code: Select all
2023-01-05 13:41:00.923 Error: Error opening url: https://api.telegram.org/botXXX:XXXXX/sendMessage?chat_id=XXXXXX&text=Mijn Energie Overzicht : 05-01-2023
2023-01-05 13:41:00.923 --------------P1 Elektriciteitmeter-----------
2023-01-05 13:41:00.923 Stroomkosten Totaal : € 3.23
2023-01-05 13:41:00.923 Stroomkosten Hoog : € 1.42
2023-01-05 13:41:00.923 Stroomkosten Laag : € 0.87
2023-01-05 13:41:00.923 Teruglevering Hoog : € 0.0
2023-01-05 13:41:00.923 Teruglevering Laag : € 0.0
2023-01-05 13:41:00.923 ---------------------------------------------------
2023-01-05 13:41:00.923 Verbruik Hoog : 3.538 kWh
2023-01-05 13:41:00.923 Verbruik Laag : 2.172 kWh
2023-01-05 13:41:00.923 Teruglevering Hoog : 0.0 kWh
2023-01-05 13:41:00.923 Teruglevering Laag : 0.0 kWh
2023-01-05 13:41:00.923 Totaal Verbruik Elektra vandaag : 5.718 kWh
2023-01-05 13:41:00.923 --------------P1 Gasmeter---------------------
2023-01-05 13:41:00.923 Gas M3 : € 0.84
2023-01-05 13:41:00.923 Totaal Verbruik Gas vandaag : 0.082 M3
2023-01-05 13:41:00.923 --------------Zonnepanelen--------------------
2023-01-05 13:41:00.923 Totaal Opbrengst Zonnepanelen : 0.0 kWh
2023-01-05 13:41:00.923 Zonopbrengst Totaal € 0.0
2023-01-05 13:41:00.923 -------------- Einde Dag Overzicht -------------
I changed the XXX by the corresponding botnumber/API and chatID....
Nothing is being sent to Telegram.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:07
by waltervl
I suppose the variable message is incorrectly formatted so dzVents or the API is ignoring the message.
Try to make a simple testmessage in the script eg
Code: Select all
local testmessage = 'Mijn TEST Energie Overzicht : ' .. os.date("%d-%m-%Y")
dz.openURL('https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=' .. testmessage)
if this works add the .. '\n second line' (for new line) eg
Code: Select all
local testmessage = 'Mijn TEST Energie Overzicht : ' .. os.date("%d-%m-%Y") .. '\n tweede lijn'
Edit: fixed typo's
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:14
by Xavier82
I get this
Code: Select all
2023-01-05 14:12:35.976 Error: dzVents: Error: (3.1.8) error loading module 'Dag verbruik in euros' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Dag verbruik in euros.lua':
2023-01-05 14:12:35.976 ...ipts/dzVents/generated_scripts/Dag verbruik in euros.lua:69: unexpected symbol near 'local'
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:20
by waltervl
I made a type error. I fixed it in my previous post.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:21
by Xavier82
after changing code to:
Code: Select all
local testmessage = 'Mijn TEST Energie Overzicht : ' .. os.date("%d-%m-%Y")
I get this:
Code: Select all
2023-01-05 14:18:00.246 Status: dzVents: Dag verbruik in euros
2023-01-05 14:18:00.246 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: url = https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=Mijn TEST Energie Overzicht : 05-01-2023
2023-01-05 14:18:00.246 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: method = GET
2023-01-05 14:18:00.246 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: post data = nil
2023-01-05 14:18:00.246 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: headers = nil
2023-01-05 14:18:00.246 Status: dzVents: Debug: Dag verbruik in euros 03/01/2023-/-v1.13: OpenURL: callback = nil
2023-01-05 14:18:00.247 Status: dzVents: Info: Dag verbruik in euros 03/01/2023-/-v1.13: ------ Finished Dag verbruik in euros
And I received a message in Telegram!:
"Mijn TEST Energie Overzicht : 05-01-2023"
UPDATE:
when adding
Code: Select all
local testmessage = 'Mijn TEST Energie Overzicht : ' .. os.date("%d-%m-%Y") .. '\n tweede lijn'
Message isn't sent anymore
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:31
by waltervl
OK so it seems the new line (\n) is the source of yor issues. It could also be that Telegram has a maximum message size. you have to check the documentation of the telegram API or find out by experiment....
So remove the '\n ..' from your script and try to buildup the message value by value.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:43
by Xavier82
So as a test I tested with de default Domoticz setup Telegram:
Code: Select all
dz.notify(subject, message, dz.PRIORITY_MEDIUM, dz.SOUND_PERSISTENT, nil, dz.NSS_TELEGRAM)
When I use this the message is being sent by Domoticz and received in Telegram (in the default chatbot as setup in Domoticz setup) incl. correct format.
I don't have a clue why this goes wrong.
Any other ideas?
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:47
by waltervl
Because the function does something special it seems...
You could try to use urlEncode() the message to see if this works:
Code: Select all
dz.openURL('https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=' .. urlEncode(message))
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:51
by Xavier82
using that code I get:
Code: Select all
2023-01-05 14:50:00.367 Error: dzVents: Error: (3.1.8) Dag verbruik in euros 03/01/2023-/-v1.13: An error occurred when calling event handler Dag verbruik in euros
2023-01-05 14:50:00.367 Error: dzVents: Error: (3.1.8) Dag verbruik in euros 03/01/2023-/-v1.13: ...ipts/dzVents/generated_scripts/Dag verbruik in euros.lua:71: attempt to call a nil value (global 'urlEncode')
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 14:54
by waltervl
try
Code: Select all
dz.openURL('https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=' .. dz.utils.urlEncode(message))
or
Code: Select all
dz.openURL('https://api.telegram.org/botXXXX:XXXX/sendMessage?chat_id=XXXX&text=' .. domoticz.utils.urlEncode(message))
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 15:01
by Xavier82
EUREKA! You're the master!
It works! Many, many, many thanks!
I really appreciate your time and patience to get this to work for me.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 15:09
by waltervl
You are welcome! Have fun with monitoring your Energy Usage on Telegram

Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 15:49
by HvdW
Hey @Xavier82
Code: Select all
local vandaagKwhzon = dz.devices('Teruglevering').counterToday -- Stroommeter p1 -Teruglevering
local vandaagKwhth = dz.devices('Teruglevering Hoog').counterToday -- Stroommeter p1 -Teruglevering Hoog
local vandaagKwhtl = dz.devices('Teruglevering Laag').counterToday -- Stroommeter p1 -Teruglevering Laag
local vandaagKwhvh = dz.devices('Verbruik Hoog').counterToday -- Stroommeter p1 -Verbruik Hoog
local vandaagKwhvl = dz.devices('Verbruik Laag').counterToday -- Stroommeter p1 -Verbruik Laag
You created dummy devices like Teruglevering, Teruglevering Hoog, Teruglevering Laag et cetera.
In my Domoticz there's just Power.
How did you assign values to these sub devices?
One more thing.
The gas consumption as it has been collected by Domoticz is only updated once an hour.
I guess your values will not reflect the exact Gas consumption of that day. (anyway, who cares)
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 16:04
by Xavier82
HvdW wrote: Thursday 05 January 2023 15:49
Hey @Xavier82
Code: Select all
local vandaagKwhzon = dz.devices('Teruglevering').counterToday -- Stroommeter p1 -Teruglevering
local vandaagKwhth = dz.devices('Teruglevering Hoog').counterToday -- Stroommeter p1 -Teruglevering Hoog
local vandaagKwhtl = dz.devices('Teruglevering Laag').counterToday -- Stroommeter p1 -Teruglevering Laag
local vandaagKwhvh = dz.devices('Verbruik Hoog').counterToday -- Stroommeter p1 -Verbruik Hoog
local vandaagKwhvl = dz.devices('Verbruik Laag').counterToday -- Stroommeter p1 -Verbruik Laag
You created dummy devices like Teruglevering, Teruglevering Hoog, Teruglevering Laag et cetera.
In my Domoticz there's just Power.
How did you assign values to these sub devices?
One more thing.
The gas consumption as it has been collected by Domoticz is only updated once an hour.
I guess your values will not reflect the exact Gas consumption of that day. (anyway, who cares)
Hi,
You need to create virtual sensors (Dummy) from the hardware menu fore these items.
I guess you are Dutch also, visit
https://www.huizebruin.nl/domoticz/slim ... z-met-lua/ for more information and instructions about this and many more interesting measurement items.
I copied scripts from that website which update the dummy devices.
My gas consumption is automatically updated every minute. I use a P1 cable which is connected to our Smart Energy meter (incl. gas) and directly to my Rpi.
The gas consumption is frighteningly accurate on day and montly level to what Essent counts and charges me.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 16:06
by Xavier82
waltervl wrote: Thursday 05 January 2023 15:09
You are welcome! Have fun with monitoring your Energy Usage on Telegram
That will work out for me for sure.
This way I hope I can keep the bills a bit tempered.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 16:26
by HvdW
Great! I'm Dutch, even better I'm Tukker.
Much simpler than
the one I have found.
The script from huize Bruin was implemented within 10 minutes.
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 16:44
by waltervl
You both know there that in the P1 Meter report page (report button on device log page) you have a detailed overview where you can see all this information per year/month even day...
https://www.domoticz.com/wiki/Dutch_DSM ... th_P1_port
Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 16:51
by Xavier82
Yup I know

but thanks for pointing out

Re: Question about notifications in dzVents
Posted: Thursday 05 January 2023 17:29
by HvdW
I did not know about the Report functionality Walter.
As always RTFM! I know, but didn't.
BTW
I learned a lot today and had a pleasant afternoon copying, coding and understanding.
Remark:
Instead of Telgram one can use Google Cloud Messaging.

- Google Cloud Messaging.jpg (28.96 KiB) Viewed 969 times
Despite that
it has been deprecated it still is alive for our purposes.
In your script:
Code: Select all
-- Notificatie voor verschillende aanbieders
-- dz.notify(subject, message, dz.PRIORITY_MEDIUM, dz.SOUND_PERSISTENT, nil, dz.NSS_TELEGRAM)
dz.notify(subject, message, dz.PRIORITY_NORMAL)
Another thing.
In your script you insert costs.
Isn't it possible to use the values added in Domoticz and how can these be extracted?

- Meters Counters.jpg (65.64 KiB) Viewed 965 times
Last remark:
What's the use of this script when one can retrieve dayly usaage and costs from your energy supplier in a nice app.