Question about notifications in dzVents

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

Moderator: leecollings

User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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
Last edited by waltervl on Thursday 05 January 2023 14:19, edited 2 times in total.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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'
Last edited by Xavier82 on Thursday 05 January 2023 14:21, edited 2 times in total.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post by waltervl »

I made a type error. I fixed it in my previous post.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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?
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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))
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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')
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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))
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post by waltervl »

You are welcome! Have fun with monitoring your Energy Usage on Telegram ;)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 664
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Question about notifications in dzVents

Post 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)
Bugs bug me.
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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.
Last edited by Xavier82 on Thursday 05 January 2023 16:15, edited 1 time in total.
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post 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.
HvdW
Posts: 664
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Question about notifications in dzVents

Post by HvdW »

Xavier82 wrote: Thursday 05 January 2023 16:04 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.
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.
Last edited by HvdW on Thursday 05 January 2023 17:22, edited 1 time in total.
Bugs bug me.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Question about notifications in dzVents

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Xavier82
Posts: 178
Joined: Tuesday 07 June 2016 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: Question about notifications in dzVents

Post by Xavier82 »

waltervl wrote: Thursday 05 January 2023 16:44 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
Yup I know 8-) but thanks for pointing out :D
HvdW
Posts: 664
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Question about notifications in dzVents

Post by HvdW »

waltervl wrote: Thursday 05 January 2023 16:44 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
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
Google Cloud Messaging.jpg (28.96 KiB) Viewed 964 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
Meters Counters.jpg (65.64 KiB) Viewed 960 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.
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest