jsiegmund wrote: ↑Sunday 21 July 2019 21:33
Ah ok, sorry. If that helps
It sure helps.
Please find below 2 dzVents scripts (one to activate the Python code and one to stop it gracefully by (re)moving the logfile) and the changed Python code.
When not yet familiar with dzVents please start with reading
Get started Before implementing. Special attention please for
"In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Please feel free to ask if something is not clear.
Code: Select all
--Activate python
return
{
on = { timer = { 'every 6 minutes' }}, -- just for the example
logging = { level = domoticz.LOG_DEBUG, marker = 'buzzer set' },
execute = function( dz )
local pyCode = '/usr/local/domotica/pysources/buzzer.py'
local buzLog = '/tmp/buzzer.log'
local seconds = 500
local backGround = '&'
local osString = 'sudo python ' .. pyCode .. ' ' .. seconds .. ' ' .. buzLog .. ' ' .. backGround
dz.log('Executing: ' .. osString,dz.LOG_DEBUG)
os.execute(osString)
end
}
Code: Select all
--stop Python
return
{
on = { timer = { 'every 4 minutes' }}, -- just for the example
logging = { level = domoticz.LOG_DEBUG, marker = 'buzzer kill' },
execute = function( dz )
local buzLog = '/tmp/buzzer.log'
local osString = 'sudo mv ' .. buzLog .. ' ' .. buzLog .. '-' .. dz.time.dDate
dz.log('Executing: ' .. osString,dz.LOG_DEBUG)
os.execute(osString)
end
}
Code: Select all
#optional args:
# 1st parm = seconds to beep
# 2nd parm = log / sentinel File
#
#Libraries
import sys
import os.path
import RPi.GPIO as GPIO # Importeer de GPIO bibliotheek.
from time import sleep ## Importeer de bibliotheek voor tijdfuncties
# default values
seconds = 5
logFile = "/tmp/buzzer.log"
buzzer_pin = 22 # Geef het nummer van de pin op waar de speaker is aangesloten.
# Set the number of seconds to the provided argument (or use default)
if len(sys.argv) > 1:
seconds = int(sys.argv[1])
# Set the log- / sentinel file (or use default)
if len(sys.argv) > 2:
logFile = sys.argv[2]
# initialize
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # GebruikBroadcom GPIO benaming van de pinnen.
GPIO.setup(buzzer_pin, GPIO.OUT) # Zet de speaker pin als uitgang.
print "seconds: " + str(seconds)
print "Druk op CTRL+C om het programma te beeindigen."
print "Of verwijder logFile (" + logFile + ")"
i = 0
f = open(logFile,"a",buffering=1) # buffering=1 ==>> flush every line
def cleanup( text ):
GPIO.output(buzzer_pin, False) # Zet speakerpin laag.
GPIO.cleanup()
print text
return
def setGPIO( bool ):
GPIO.output(buzzer_pin, bool) # Zet speakerpin.
sleep(.5)
return
try:
while i < seconds and os.path.exists(logFile):
setGPIO(True)
setGPIO(False)
i += 1
logLine = "buzzer buzzed " + str(i) + " times\n"
f.write(logLine);
except KeyboardInterrupt:
cleanup("GPIO netjes afsluiten (Keyboard interrupt)")
except OSError:
cleanup("GPIO netjes afsluiten (OS error)")
else:
cleanup("GPIO netjes afsluiten (normal end)")
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki