Scrips with variable input in blocky events

Moderator: leecollings

Post Reply
Duan
Posts: 9
Joined: Saturday 20 February 2016 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Scrips with variable input in blocky events

Post 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
Attachments
Screen Shot 2016-07-03 at 11.58.49.png
Screen Shot 2016-07-03 at 11.58.49.png (58.81 KiB) Viewed 2172 times
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Scrips with variable input in blocky events

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Duan
Posts: 9
Joined: Saturday 20 February 2016 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Scrips with variable input in blocky events

Post 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!
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Scrips with variable input in blocky events

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Scrips with variable input in blocky events

Post 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
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Scrips with variable input in blocky events

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Scrips with variable input in blocky events

Post by Derik »

Sorry for my bad communication [ my Enblisch :-( ]

When i make a LUA here:
ScreenShot076.jpg
ScreenShot076.jpg (154.83 KiB) Viewed 2100 times
Where can i find it here:
ScreenShot075.jpg
ScreenShot075.jpg (65.71 KiB) Viewed 2100 times
Because i make a backup weekly of all my scripts...[ save a lot of time when my Domoticz crashed ]
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Scrips with variable input in blocky events

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest