python script to lua
Moderator: leecollings
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
python script to lua
can someone help me to convert this pyhon script to a lua script because the script works in the command line but not in domoticz on action.
treid everything
this is the python script:
#!/usr/bin/python3
#import libraries
import os
import time
# Start the servo motors
os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod')
# turn servo 0 to 10% position
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2.5)
# turn servo 0 to 60% position
os.system("echo 7=50% > /dev/servoblaster")
time.sleep(3)
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2)
os.system("echo 7=100% > /dev/servoblaster")
time.sleep(1)
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2)
# Stop the servo motors
os.system('sudo killall servod')
treid everything
this is the python script:
#!/usr/bin/python3
#import libraries
import os
import time
# Start the servo motors
os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod')
# turn servo 0 to 10% position
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2.5)
# turn servo 0 to 60% position
os.system("echo 7=50% > /dev/servoblaster")
time.sleep(3)
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2)
os.system("echo 7=100% > /dev/servoblaster")
time.sleep(1)
os.system("echo 7=10% > /dev/servoblaster")
time.sleep(2)
# Stop the servo motors
os.system('sudo killall servod')
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
I am doing something similar but use a bash script in the On action, which then shells another Bash script.
Main reason for this approach was to avoid hanging the event system while the action was running.
You could use a similar approach and shell a python script by just updating the below code.
The last & ensures the script returns immediately leaving the second script running in the background.
Jos
Main reason for this approach was to avoid hanging the event system while the action was running.
You could use a similar approach and shell a python script by just updating the below code.
The last & ensures the script returns immediately leaving the second script running in the background.
Code: Select all
#!/bin/bash
#--Check if script is already running and only start it when it isn't running yet.
chk=`sudo ps x | grep "Blinds_Set.sh 0" | grep -cv grep`
if [ "$chk" = "0" ] ; then
sh /home/pi/domoticz/scripts/Blinds_Set.sh >> /var/tmp/blinds.log 2>&1 &
#--else
#-- echo "$(date +%x) $(date +%X) Blinds_Set.sh is already running" >> /var/tmp/blinds.log
fi
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
i tried to run the python script trough a bash script but it didnt work,
in comend line it did
thats why i want it in a lua script. but i dont know how to do it
in comend line it did
thats why i want it in a lua script. but i dont know how to do it
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
How does the commandline you want to start look exactly?
Do you use the fully qualified path for the python file?
Jos
Do you use the fully qualified path for the python file?
Jos
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
I used for on script:///home/domoticz/scripts/python/servoscript.py
And also tried script:///home/domoticz/scripts/servoscript.sh
And
Script://scripts/python/servoscript.py
And also tried script:///home/domoticz/scripts/servoscript.sh
And
Script://scripts/python/servoscript.py
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
No ... I mean what is the commandline you used in the Bash file that isn't working and the commandline that is working?
Also: what is the content of script: script:///home/domoticz/scripts/servoscript.sh ?
Jos
Also: what is the content of script: script:///home/domoticz/scripts/servoscript.sh ?
Jos
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
Content is:
#!/bin/bash
python3 /home/pi/domoticz/scripts/python/servoscript.py
exit 0
From the command line i do: python servoscript.py this works
And : ./servoscript.sh also works from the commandline
#!/bin/bash
python3 /home/pi/domoticz/scripts/python/servoscript.py
exit 0
From the command line i do: python servoscript.py this works
And : ./servoscript.sh also works from the commandline
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
Did you set the x attribute for them to allow them to be executed?
Don't forget to add the & to the end of the command to avoid hanging the event system for the duration of the script.
Jos
Don't forget to add the & to the end of the command to avoid hanging the event system for the duration of the script.
Jos
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
I did chmod +x
And tried sudo chmod +x
And tried sudo chmod +x
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
So what happens when you have this in /home/domoticz/scripts/servoscript.sh:
.. and you check the logfile for any feeedback? : /var/tmp/test.log
Change the path for the logfile to anything your system supports.
And use the On Action: script:///home/domoticz/scripts/servoscript.sh
Jos
Code: Select all
#!/bin/bash
python3 /home/pi/domoticz/scripts/python/servoscript.py >> /var/tmp/test.log 2>&1 &
exit 0Change the path for the logfile to anything your system supports.
And use the On Action: script:///home/domoticz/scripts/servoscript.sh
Jos
-
febalci
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: python script to lua
Did you tried:
script:///usr/bin/python3 /home/domoticz/scripts/python/servoscript.py (assuming python3 is under /usr/bin)
Also the same goes for bash:
#!/bin/bash
/usr/bin/python3 /home/pi/domoticz/scripts/python/servoscript.py
And you better put your bash file under:
/home/domoticz/scripts/bash/
Additionally maybe there could be something wrong with:
os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod')
It might require user input like password??
script:///usr/bin/python3 /home/domoticz/scripts/python/servoscript.py (assuming python3 is under /usr/bin)
Also the same goes for bash:
#!/bin/bash
/usr/bin/python3 /home/pi/domoticz/scripts/python/servoscript.py
And you better put your bash file under:
/home/domoticz/scripts/bash/
Additionally maybe there could be something wrong with:
os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod')
It might require user input like password??
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
Thanks for your help, i will try it tomorow,
I am at a party now
I am at a party now
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
hi jvz
script:///home/domoticz/scripts/servoscript.sh
Gives this in the domoticz log:
Error: Error executing script command (/usr/bin/python3). returned: -1
and in /var/tmp/test.log i get nothing
i just dont get it if i ssh into the pi and execute the script it works perfectly
script:///home/domoticz/scripts/servoscript.sh
Gives this in the domoticz log:
Error: Error executing script command (/usr/bin/python3). returned: -1
and in /var/tmp/test.log i get nothing
i just dont get it if i ssh into the pi and execute the script it works perfectly
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
hi jvdz
i did what you asked, i get no results in the log file with the on action.
if i ssh in to the pi and execute servoscript.sh there
i get this in var/tmp/test.log:
Board model: 1
GPIO configuration: P1 (40 pins)
Using hardware: PWM
Using DMA channel: 14
Idle timeout: Disabled
Number of servos: 8
Servo cycle time: 20000us
Pulse increment step size: 10us
Minimum width value: 50 (500us)
Maximum width value: 250 (2500us)
Output levels: Normal
Using P1 pins: 7,11,12,13,15,16,18,22
Servo mapping:
0 on P1-7 GPIO-4
1 on P1-11 GPIO-17
sorry if i dont understand you but iam new to linux and scripting
i did what you asked, i get no results in the log file with the on action.
if i ssh in to the pi and execute servoscript.sh there
i get this in var/tmp/test.log:
Board model: 1
GPIO configuration: P1 (40 pins)
Using hardware: PWM
Using DMA channel: 14
Idle timeout: Disabled
Number of servos: 8
Servo cycle time: 20000us
Pulse increment step size: 10us
Minimum width value: 50 (500us)
Maximum width value: 250 (2500us)
Output levels: Normal
Using P1 pins: 7,11,12,13,15,16,18,22
Servo mapping:
0 on P1-7 GPIO-4
1 on P1-11 GPIO-17
sorry if i dont understand you but iam new to linux and scripting
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
Are you sure you did put this in there: "script:///home/domoticz/scripts/servoscript.sh"edwin1234 wrote: Sunday 10 December 2017 7:14 Error: Error executing script command (/usr/bin/python3). returned: -1
..and not "script:///usr/bin/python3 /home/domoticz/scripts/python/servoscript.py " like @febalci suggested?
Jos
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
Another thing to check is whether the permissions are set correctly for both files!
Jos
Jos
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
no with youre sugestion i get this:
10:18:35.495 Error: Error executing script command (/home/pi/domoticz/scripts/servoscript.sh). returned: -1
10:18:35.495 Error: Error executing script command (/home/pi/domoticz/scripts/servoscript.sh). returned: -1
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
must i do chmod +x for both files or
sudo chmod +x for both files?
sudo chmod +x for both files?
- jvdz
- Posts: 2441
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: python script to lua
The "sudo chmod +x " will only set the execute flag.
To allow everybody access you could do : "sudo chmod 777" for both files.
Jos
To allow everybody access you could do : "sudo chmod 777" for both files.
Jos
-
edwin1234
- Posts: 330
- Joined: Sunday 09 October 2016 20:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Nederland
- Contact:
Re: python script to lua
i did sudo chmod 777 on both files
but still the same error in the domoticz log
Error: Error executing script command (/home/pi/domoticz/scripts/servoscript.sh). returned: -1
but still the same error in the domoticz log
Error: Error executing script command (/home/pi/domoticz/scripts/servoscript.sh). returned: -1
Who is online
Users browsing this forum: No registered users and 1 guest