dzvents is using variables from other script

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

Moderator: leecollings

Post Reply
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzvents is using variables from other script

Post by corthebor »

Today I received a (Telegram) message "Sunscreen is going up" and this was sent by a script that nothing had to do with my sunscreen.
I found out that the script which turns on the lights should have sent the message "Lights going on" but used the message from the sunscreen-script .
the problem was the fact that I use the same line in both scripts:

os.execute('curl --data chat_id='..chatid..' --data-urlencode "text='..message..'" "https://api.telegram.org/bot'..token..'/sendMessage" ')

The variable: message is defined at the beginning of each script:
message = 'Sunscreen is going up' --> for the sunscreen-script
message = 'Lights going on' --> for the lamp-script

Does anyone know how to avoid this? besides that I have to rename all messages in the scripts with different names?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents is using variables from other script

Post by waaren »

corthebor wrote: Thursday 18 April 2019 21:05 Today I received a (Telegram) message "Sunscreen is going up" and this was sent by a script that nothing had to do with my sunscreen.
I found out that the script which turns on the lights should have sent the message "Lights going on" but used the message from the sunscreen-script .
the problem was the fact that I use the same line in both scripts:

os.execute('curl --data chat_id='..chatid..' --data-urlencode "text='..message..'" "https://api.telegram.org/bot'..token..'/sendMessage" ')

The variable: message is defined at the beginning of each script:
message = 'Sunscreen is going up' --> for the sunscreen-script
message = 'Lights going on' --> for the lamp-script

Does anyone know how to avoid this? besides that I have to rename all messages in the scripts with different names?
Best practice in programming is to limit the scope of variables as much as possible. In this case you could start with changing the declaration of these vars from

Code: Select all

message = 'Sunscreen is going up'         --> for the sunscreen-script
message = 'Lights going on'           --> for the lamp-script
to

Code: Select all

local message = 'Sunscreen is going up'         --> for the sunscreen-script
local message = 'Lights going on'           --> for the lamp-script
On a side note: domoticz.notify can natively send a notification to telegram since dzVents version 2.4.8
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents is using variables from other script

Post by corthebor »

@waaren

Thanks for the reply. I'll keep that in mind.

About domoticz.notify can natively send a notification to telegram: I looked in to that a while ago, but did not manage to get that working.

I will give it a try one of these days.

gr. Cor
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents is using variables from other script

Post by waaren »

corthebor wrote: Friday 19 April 2019 9:23 About domoticz.notify can natively send a notification to telegram: I looked in to that a while ago, but did not manage to get that working.
in Domoticz [Setup] [Settings] [Notifications]
Telegram setup
Telegram setup
telegramSetup.png (13.58 KiB) Viewed 697 times
in your dzVents script:

Code: Select all

domoticz.notify("Subject", "message",domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_TELEGRAM)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents is using variables from other script

Post by corthebor »

@waaren
Thanks
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents is using variables from other script

Post by corthebor »

On a side note: domoticz.notify can natively send a notification to telegram since dzVents version 2.4.8
I managed to have the domoticz.notify command working but I changed back to the curl command because I received notifications on all configured services. (Email, pushover, telegram etc..).
I better wait until the next (stable) update from domoticz to version 4.10200 (dzVents 2.4.8)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents is using variables from other script

Post by waaren »

corthebor wrote: Saturday 20 April 2019 11:15
On a side note: domoticz.notify can natively send a notification to telegram since dzVents version 2.4.8
I managed to have the domoticz.notify command working but I changed back to the curl command because I received notifications on all configured services. (Email, pushover, telegram etc..).
I better wait until the next (stable) update from domoticz to version 4.10200 (dzVents 2.4.8)
That should not happen if you are on dzVents 2.4.8 and use the line

Code: Select all

domoticz.notify("Subject", "message",domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_TELEGRAM)
If you share your script I will have a look and see what goes wrong.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents is using variables from other script

Post by corthebor »

This is my stable version of domoticz and dzvents and there is no update available for now...
And I would rather not change to the beta version

Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 16:24:51
dzVents Version: 2.4.6
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents is using variables from other script

Post by waaren »

corthebor wrote: Saturday 20 April 2019 11:51 This is my stable version of domoticz and dzvents and there is no update available for now...
And I would rather not change to the beta version

Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 16:24:51
dzVents Version: 2.4.6
Understand. Can you try this in your current version ?

Code: Select all

domoticz.notify("Subject", "message",domoticz.PRIORITY_NORMAL,nil,nil,"telegram")
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzvents is using variables from other script

Post by corthebor »

Ok, missed that.
Is working like it should be.
Thanks again
Post Reply

Who is online

Users browsing this forum: andrehj and 0 guests