Ad nauseam: script works in terminal but not Domoticz

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
Apexdv
Posts: 6
Joined: Tuesday 19 May 2015 20:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Seattle US
Contact:

Ad nauseam: script works in terminal but not Domoticz

Post by Apexdv »

Hi all ... first, please be gentle - I've been yelled at and put down quite a bit here for not understanding programming so ...

I'm attempting to simply play a door chime mp3 when a contact switch opens. Took me a while but I finally figured out how to get the simple contact switch working. Resistor to 3.3v?? Who knew? Not me. haha

The script works perfectly within a terminal but, as has all too often been mentioned in these forums, does not within Domoticz.

Script is simple: /home/pi/domoticz/scripts/doorchime.sh

Code: Select all

#!/bin/bash
# Play the door chime
mplayer -volume 80 /home/pi/domoticz/sounds/cabin_chime.mp3 > /dev/null 2>&1
User "pi" is in the audio group

Code: Select all

pi@NorthwoodDeux:~/domoticz/scripts $ id
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),117(lpadmin),997(gpio),998(i2c),999(spi)
I understand that commands sent from within Domoticz are root'ed (correct verbiage?) so I found this: https://domoticz.com/forum/viewtopic.php?t=31174 but it does not work for me at all. Even in the terminal I get nothing.

I've attempted calling the script via the "On action" function directly in the device:

Code: Select all

script:///home/pi/domoticz/scripts/doorchime.sh
and have even tried

Code: Select all

script://doorchime.sh
all to no avail.

I've attempted using dzVents and tested the os.execute command several ways using a motion sensor as the trigger (easier than opening/closing the switch right now)

Code: Select all

return {
	on = {
		devices = {
			'PIR_MotionSensor'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'whoops thar be motion in da hizzle',
	},
	execute = function(domoticz, device)
	    os.execute ("runuser -l pi -c \'mplayer -volume 80 /home/pi/domoticz/sounds/cabin_chime.mp3'")
		domoticz.log('PIR_MotionSensor' .. device.name .. ' got a little jiggy', domoticz.LOG_INFO)
	end
}
This, too, failed.

I've gone as far as completely wiping the SD card and starting from scratch to no avail. I did have this same issue several years back (5 or so?) when I first began using Domoticz but was able to get it working although, I cannot recall how.

user "pi" is in the audio group
runuser does not seem to work in this instance
script works perfectly and be called from within other scripts within terminal

I'm unsure how to code this within dzVents to display an error code that could possibly help identify an issue. I'm not a coder but am pretty adept at learning and have become quite comfy with LUA although I'm now preferring dzVents - all self-taught.

Does anyone have any suggestions on what to check next or how to script dzVents to reveal any error codes? I'm kinda pulling my hair out on something that seems should be quite simple. Every single thread I've viewed on this topic - and there are many! - their resolution did not work for me.

Did I provide enough information or is there something else I should add to clarify?

Thanks in advance.
Apexdv
Posts: 6
Joined: Tuesday 19 May 2015 20:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Seattle US
Contact:

Re: Ad nauseam: script works in terminal but not Domoticz

Post by Apexdv »

Errrrmmmmm ... seriously, three minutes after posting I walked into the kitchen which activated the PIR and "derrn donnn". It worked. I have no idea what has changed but I now have the chime working.

Thanks again. Still, if anyone can think of anything I should have added to help with discovery please list it as it will be useful should I have questions in the future.

Thanks!
User avatar
waltervl
Posts: 5399
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Ad nauseam: script works in terminal but not Domoticz

Post by waltervl »

Well does it work now through dzVents or through the action scripts?
And when testing did you see the bash scripts getting started in the Domoticz logging?
If you did
sudo /home/pi/domoticz/scripts/doorchime.sh
to test the root route, did this work?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Apexdv
Posts: 6
Joined: Tuesday 19 May 2015 20:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Seattle US
Contact:

Re: Ad nauseam: script works in terminal but not Domoticz

Post by Apexdv »

It now is working via the dzVents script. I changed the script over to work with the contact switch rather than the PIR and it is working perfectly

Code: Select all

return {
	on = {
		devices = {
			'Front Door'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Switch activated',
	},
	execute = function(domoticz, device)
	    os.execute ("runuser -l pi -c \'mplayer -volume 80 /home/pi/domoticz/sounds/cabin_chime.mp3'")
		domoticz.log('Front Door' .. device.name .. ' was opened or closed', domoticz.LOG_INFO)
	end
}
The next step will be to figure out how to activate only on the on/open so the chime does not sound when the door is closed but, that's minor.

I did look in the logs but did not see anything so I'm wondering if my loglevel is even set appropriately. I'll check into that shortly when I get everything moved over to a USB flash drive (new Pi).
Apexdv
Posts: 6
Joined: Tuesday 19 May 2015 20:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Seattle US
Contact:

Re: Ad nauseam: script works in terminal but not Domoticz

Post by Apexdv »

waltervl wrote: Friday 11 June 2021 19:48 Well does it work now through dzVents or through the action scripts?
And when testing did you see the bash scripts getting started in the Domoticz logging?
If you did
sudo /home/pi/domoticz/scripts/doorchime.sh
to test the root route, did this work?
Oh and I did attempt executing the script using sudo through root. It does not work. If I run it as the standard user, pi, it works fine.

I'm still curious as to what changed to cause it to begin working. I somehow think I had perhaps an extra "." or something somewhere I did not notice and by chance deleted it my mistake? Dunno.

BUT it is working now. Strange.
Apexdv
Posts: 6
Joined: Tuesday 19 May 2015 20:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Seattle US
Contact:

Re: Ad nauseam: script works in terminal but not Domoticz

Post by Apexdv »

I save each script as a version in order to allow tracing back to see if any specific changes worked or failed and I found where I made my mistake. When calling the mp3 directly using os.execute along with runuser I entered the file name as cabinchime.mp3 rather than the correct form of cabin_chime.mp3.

The error was completely in my hands but it does tell me what solved the issue for me was using the "runuser" command. I've since went back and tested the os.execute with and without "runuser" ... it's definitely a rights thing with mplayer ignoring root entirely.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests