Enigma2Events: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Enigma2 Events = the VTi images used by vu-uno and vuzero run scripts on the following events: * DBTASK_CANCEL * DBTASK_FINISH * DBTASK_START * E2START * GUI_REBOOT * PVRDESCRAMBLE_START * PVRDESCRAMBLE_STOP * REBOOT * RECORD_REMIND * RECORD_START * RECORD_STOP * RECORD_WAKEUP * SERVICE_START * SERVICE_STOP * SHUTDOWN * STANDBY_ENTER * STANDBY_LEAVE * STBBOOT * TASK_CANCEL * TASK_FINISH * TASK_START I use them to switch the AV receiver on and off by sending a http r...") |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 25: | Line 25: | ||
* TASK_START | * TASK_START | ||
I use them to switch the AV receiver on and off | I use them to switch the AV receiver on and off. | ||
The commands for the different events are in /etc/enigma2/events | At first a http request was sent to a tasmota switch. | ||
The commands for the different events are in /etc/enigma2/events. E.g. STANDBY_ENTER.sh: | |||
see | #!/bin/sh | ||
OUT=`wget -O- -q 'http://nous4/cm?cmnd=Power%20Off' 2>&1` | |||
echo "${0##*/}: $OUT" > /dev/udp/192.168.1.4/514 | |||
exit 0 | |||
Now I use my mqtt-to-serial rx-v1600 gateway with my /etc/enigma2/events/rxv-toggle.py. | |||
It also switches the av input and handles fast stb toggling much better. | |||
<nowiki> | |||
#!/usr/bin/python | |||
# Send commands to switch RX-V1600 on or off | |||
# Requires https://github.com/joba-1/Joba_RxV1600/tree/master/examples/Mqtt_RxV1600 | |||
# (c) Joachim Banzhaf, 2023 | |||
pid_file = '/var/run/rxv-toggle.pid' | |||
cmd_topic = 'Mqtt_RxV1600/2/cmd' | |||
syslog_server = 'job4' | |||
mqtt_broker = 'job4' | |||
# Register signal handlers for signals TERM and INT to allow atexit to do its job | |||
import signal | |||
def signal_exit(signum, frame): | |||
exit(0) | |||
signal.signal(signal.SIGTERM, signal_exit) | |||
signal.signal(signal.SIGINT, signal_exit) | |||
# Kill earlier incarnation of us, if any | |||
try: | |||
with open(pid_file, 'r') as f: | |||
pid = int(f.read()) | |||
os.kill(pid, signal.SIGTERM) | |||
except Exception: | |||
pass | |||
# Register atexit handler to remove our pid file | |||
import atexit | |||
import os | |||
import sys | |||
import logging | |||
from logging.handlers import SysLogHandler | |||
logger = logging.getLogger() | |||
logger.addHandler(SysLogHandler(address=(syslog_server, 514))) | |||
logger.setLevel(logging.INFO) | |||
def atexit_cleanup(): | |||
try: | |||
os.remove(pid_file) | |||
except OSError: | |||
pass | |||
finally: | |||
logger.info('{}: ended'.format(sys.argv[0])) | |||
atexit.register(atexit_cleanup) | |||
# Write our pid file and log a start message | |||
with open(pid_file, 'w') as f: | |||
f.write(str(os.getpid())) | |||
logger.info('{}: start'.format(sys.argv[0])) | |||
# Finally send RX-V1600 commands | |||
import paho.mqtt.client as mqtt | |||
import time | |||
def on_connect(client, userdata, flags, rc): | |||
logger.info('{}: mqtt connected with rc={}'.format(sys.argv[0], str(rc))) | |||
mc = mqtt.Client() | |||
mc.on_connect = on_connect | |||
mc.connect(mqtt_broker) | |||
mc.loop_start() | |||
if len(sys.argv) > 1 and sys.argv[1].lower() == 'on': | |||
mc.publish(cmd_topic, "MainZonePower_On").wait_for_publish() | |||
time.sleep(5) | |||
mc.publish(cmd_topic, "SpeakerRelayB_Off").wait_for_publish() | |||
time.sleep(0.1) | |||
mc.publish(cmd_topic, "Input_Dtv").wait_for_publish() | |||
time.sleep(0.1) | |||
mc.publish(cmd_topic, "SpeakerRelayA_On").wait_for_publish() | |||
time.sleep(0.1) | |||
else: | |||
mc.publish(cmd_topic, "MainZonePower_Off").wait_for_publish() | |||
time.sleep(0.1) | |||
</nowiki> | |||
where the evens scripts just contain | |||
#!/bin/sh | |||
exec "${0%/*}/rxv-toggle.py" on|off | |||
see [https://www.boxpirates.to/index.php?thread/203570-vti-image-14-x-x-update-infos/&postID=951431#post951431 VTi Image 14.x.x Update Infos] | |||
== MQTT with Python == | |||
recently I added the ability to publish mqtt topics: | |||
* download python module paho mqtt from github as zip (vu-uno python has no pip) | |||
* copy zip to the vu-uno | |||
cat /home/joachim/Downloads/paho.mqtt.python-master.zip | ssh vu-uno 'cat >/home/joachim/paho.zip' | |||
ssh root@vu-uno | |||
opkg update | |||
opkg install py-compile | |||
cd /home/joachim | |||
unzip paho.zip | |||
cd paho.mqtt.python-master | |||
python setup.py install | |||
* fix bug about missing pre connect callback (v1.6.1 as of Nov 2023) | |||
** vi /usr/lib/python2.7/site-packages/paho_mqtt-1.6.1-py2.7.egg/paho/mqtt/client.py | |||
** search for self._on_disconnect (in class Client) | |||
** add similar line nearby: self._on_pre_connect = None | |||
Now you can publish mqtt topics with this simple python code: | |||
#!/usr/bin/python | |||
import paho.mqtt.publish as publish | |||
publish.single("some/topic", "some-value", hostname="your-mqtt-broker") | |||
Latest revision as of 01:04, 19 December 2023
Enigma2 Events
the VTi images used by vu-uno and vuzero run scripts on the following events:
- DBTASK_CANCEL
- DBTASK_FINISH
- DBTASK_START
- E2START
- GUI_REBOOT
- PVRDESCRAMBLE_START
- PVRDESCRAMBLE_STOP
- REBOOT
- RECORD_REMIND
- RECORD_START
- RECORD_STOP
- RECORD_WAKEUP
- SERVICE_START
- SERVICE_STOP
- SHUTDOWN
- STANDBY_ENTER
- STANDBY_LEAVE
- STBBOOT
- TASK_CANCEL
- TASK_FINISH
- TASK_START
I use them to switch the AV receiver on and off. At first a http request was sent to a tasmota switch. The commands for the different events are in /etc/enigma2/events. E.g. STANDBY_ENTER.sh:
#!/bin/sh OUT=`wget -O- -q 'http://nous4/cm?cmnd=Power%20Off' 2>&1` echo "${0##*/}: $OUT" > /dev/udp/192.168.1.4/514 exit 0
Now I use my mqtt-to-serial rx-v1600 gateway with my /etc/enigma2/events/rxv-toggle.py. It also switches the av input and handles fast stb toggling much better.
#!/usr/bin/python
# Send commands to switch RX-V1600 on or off
# Requires https://github.com/joba-1/Joba_RxV1600/tree/master/examples/Mqtt_RxV1600
# (c) Joachim Banzhaf, 2023
pid_file = '/var/run/rxv-toggle.pid'
cmd_topic = 'Mqtt_RxV1600/2/cmd'
syslog_server = 'job4'
mqtt_broker = 'job4'
# Register signal handlers for signals TERM and INT to allow atexit to do its job
import signal
def signal_exit(signum, frame):
exit(0)
signal.signal(signal.SIGTERM, signal_exit)
signal.signal(signal.SIGINT, signal_exit)
# Kill earlier incarnation of us, if any
try:
with open(pid_file, 'r') as f:
pid = int(f.read())
os.kill(pid, signal.SIGTERM)
except Exception:
pass
# Register atexit handler to remove our pid file
import atexit
import os
import sys
import logging
from logging.handlers import SysLogHandler
logger = logging.getLogger()
logger.addHandler(SysLogHandler(address=(syslog_server, 514)))
logger.setLevel(logging.INFO)
def atexit_cleanup():
try:
os.remove(pid_file)
except OSError:
pass
finally:
logger.info('{}: ended'.format(sys.argv[0]))
atexit.register(atexit_cleanup)
# Write our pid file and log a start message
with open(pid_file, 'w') as f:
f.write(str(os.getpid()))
logger.info('{}: start'.format(sys.argv[0]))
# Finally send RX-V1600 commands
import paho.mqtt.client as mqtt
import time
def on_connect(client, userdata, flags, rc):
logger.info('{}: mqtt connected with rc={}'.format(sys.argv[0], str(rc)))
mc = mqtt.Client()
mc.on_connect = on_connect
mc.connect(mqtt_broker)
mc.loop_start()
if len(sys.argv) > 1 and sys.argv[1].lower() == 'on':
mc.publish(cmd_topic, "MainZonePower_On").wait_for_publish()
time.sleep(5)
mc.publish(cmd_topic, "SpeakerRelayB_Off").wait_for_publish()
time.sleep(0.1)
mc.publish(cmd_topic, "Input_Dtv").wait_for_publish()
time.sleep(0.1)
mc.publish(cmd_topic, "SpeakerRelayA_On").wait_for_publish()
time.sleep(0.1)
else:
mc.publish(cmd_topic, "MainZonePower_Off").wait_for_publish()
time.sleep(0.1)
where the evens scripts just contain
#!/bin/sh
exec "${0%/*}/rxv-toggle.py" on|off
see VTi Image 14.x.x Update Infos
MQTT with Python
recently I added the ability to publish mqtt topics:
- download python module paho mqtt from github as zip (vu-uno python has no pip)
- copy zip to the vu-uno
cat /home/joachim/Downloads/paho.mqtt.python-master.zip | ssh vu-uno 'cat >/home/joachim/paho.zip' ssh root@vu-uno opkg update opkg install py-compile cd /home/joachim unzip paho.zip cd paho.mqtt.python-master python setup.py install
- fix bug about missing pre connect callback (v1.6.1 as of Nov 2023)
- vi /usr/lib/python2.7/site-packages/paho_mqtt-1.6.1-py2.7.egg/paho/mqtt/client.py
- search for self._on_disconnect (in class Client)
- add similar line nearby: self._on_pre_connect = None
Now you can publish mqtt topics with this simple python code:
#!/usr/bin/python
import paho.mqtt.publish as publish
publish.single("some/topic", "some-value", hostname="your-mqtt-broker")