Page 1 of 1
Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 12:09
by Duan
Hello all,
Consider this as a newbie question.
I have blocky events and also scripts that are running fine and I would like to combine them.
For example when I turn a dummy switch on, on a sunday, I want to send my a Telegram message to my girlfriend (see attachment).
Lua Script command:
Code: Select all
script:///home/pi/tg/scripts/generic/telegram.sh msg 'GirlFriend' "Goodmorning sweetheart"
Usually I use a workaround by creating an scene that runs a script when turned on.
But in this case the script has in input of a string that is variable, which means I should make a lot of scene's with different text as input.
Hopefully one of you guys has a creative way to solve this!
Kind regards,
Duan
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 12:31
by jvdz
I use a LUA script for this either by the build-in editor ( select LUA and DEVICE in the appropriate boxes) or a file call script_device_xxxxx.lua in the LUA subdir:
Code: Select all
commandArray = {}
-- Send telegram message to "Both" or "Jos" or "Partner"
function TelegramMsg(id, message, silent)
-- Specify the Telegram BOT Token string
token = "9999999999:AAxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx"
-- Specify the 2 Telegram ID's for my partner and me
JosId = 12345678
PartnerId = 11122223
-- Define sending text without notification
silent_str = " "
if silent == nil then
silent_str = " "
elseif silent == 1 then
silent_str = ' --data disable_notification=true'
end
-- Select who to send the message to (Either one or both)
if (id == 'Both' or id == 'Jos' or id == JosId) then
os.execute('curl --data chat_id='..JosId..silent_str..' --data-urlencode "text=*'..message..'" "https://api.telegram.org/bot'..token..'/sendMessage" &')
end
if (id == 'Both' or id == 'Partner' or id == PartnerId) then
os.execute('curl --data chat_id='..PartnerId..' --data-urlencode "text='..message..'" "https://api.telegram.org/bot'..token..'/sendMessage" &')
end
end
if (devicechanged['Dummy light'] == "On") then
-- Send Telegram to Both Cellphone with notification
TelegramMsg("Both", "Demo telegram")
-- Send Telegram to Jos's Cellphone without notification
TelegramMsg("Jos", "Demo telegram", 1)
end
return commandArray
Jos
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 18:13
by Duan
In the private chat you suggested to use the bot wiki instead of the non-bot wiki. Sending messages from Domoticz works like a charm and the setup was much faster. I solved my issue by replacing the script by a Telegram API request
Code: Select all
https://api.telegram.org/bot0000000:KEYKEYKEYKEYKEYKEY/sendMessage?chat_id=12345678&text=test
Thanks Jos!
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 18:28
by jvdz
Correct, and the LUA code I posted is also using the API format and is a "simpler" way of sending a notification to 1 or 2 telegram ID's from any LUA script, which I needed for my setup.
I have actually put the function in a general.lua file which I include in each script I write, so I have any of these functions in the library available in each script.
Enjoy,
Jos
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 21:26
by Derik
Looks great..
Almost holiday..
This is on my wishlist!!!
Jos is there a option to ad more users...
I do have a few kids that i want to send some "orders" when they..... forget the ..xxx
Where is the place of the LUA scripts that i make in the "gebeurtenissen" area
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 21:40
by jvdz
Derik wrote:Jos is there a option to ad more users...
Should be pretty easy in the script. Just add the variables and the if's to the posted code.
Derik wrote:Where is the place of the LUA scripts that i make in the "gebeurtenissen" area
Not sure I understand the question. I am running Domoticz in English so am guessing a little here:
I am not using the internal Events (Gebeurtenissen) editor at all myself neither for Blockly or LUA and have all my LUA scripts stored in domoticz\scripts\lua using the proper naming convention as described in the Events WiKi:
https://www.domoticz.com/wiki/Events .
It should all work fine too when using the internal editor though, so maybe you can explain what you are looking for exactly here?
Jos
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 21:51
by Derik
Sorry for my bad communication [ my Enblisch
]
When i make a LUA here:
- ScreenShot076.jpg (154.83 KiB) Viewed 2107 times
Where can i find it here:
- ScreenShot075.jpg (65.71 KiB) Viewed 2107 times
Because i make a backup weekly of all my scripts...[ save a lot of time when my Domoticz crashed ]
Re: Scrips with variable input in blocky events
Posted: Sunday 03 July 2016 21:54
by jvdz
You won't find any files for the internal script editor scripts, as these scripts are stored in the domoticz.db, where also all other data is stored for domoticz, as far as I know. So you should be good when you have that in your backup process.
Jos