Page 1 of 1

dzvents is using variables from other script

Posted: Thursday 18 April 2019 21:05
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?

Re: dzvents is using variables from other script

Posted: Thursday 18 April 2019 21:27
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

Re: dzvents is using variables from other script

Posted: Friday 19 April 2019 9:23
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

Re: dzvents is using variables from other script

Posted: Friday 19 April 2019 9:41
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 797 times
in your dzVents script:

Code: Select all

domoticz.notify("Subject", "message",domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_TELEGRAM)

Re: dzvents is using variables from other script

Posted: Friday 19 April 2019 10:14
by corthebor
@waaren
Thanks

Re: dzvents is using variables from other script

Posted: Saturday 20 April 2019 11:15
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)

Re: dzvents is using variables from other script

Posted: Saturday 20 April 2019 11:22
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.

Re: dzvents is using variables from other script

Posted: Saturday 20 April 2019 11:51
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

Re: dzvents is using variables from other script

Posted: Saturday 20 April 2019 12:47
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")

Re: dzvents is using variables from other script

Posted: Saturday 20 April 2019 17:37
by corthebor
Ok, missed that.
Is working like it should be.
Thanks again