Linux - [RELEASE]Plugin for Timer- and Powermanagement in XBMC/Kodi and TVHeadend

  Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #1
First of all, I’m not shure if this is the right place for announcment or maybe the next subforum (Python development), second I thank nmcaullay for inspiration and parts of source code from his pvruptime-addon (see http://forum.xbmc.org/showthread.php?p=7...post725958) and at least, sorry for my bad english.

Ok lets go!

The described addon here is hosted by the german “VDR-Portal” where you can find the download/screenshots of this addon too.

http://www.vdr-portal.de/board60-linux/b...ost1024670

Download (new download location): http://vdr4bj1.no-ip.org

The combination of XBMC(Buntu) and TVHeadend as backend hasn’t a power or timer management for ongoing and upcoming recordings. A wake-up mechanism for future recordings either under XBMC nor under TVHeadend isn't completed yet or needs several bash scriptings. Therefore I've written a Python-Script, which is registered as a service on XBMC running in Frodo, Gotham and hopefully in later versions if needed.

The operation of this script can be summarized as follows:
    a pressure on the power button on the remote control whilest a current or soon upcoming recording is ignored and an appropriate message is shown. After recording and analyzing for next possible timers a wake-up via ACPI or NVRAM (nvram-wakeup must be installed and properly configured) is set and the system shuts down.
    Every keypress (Play, Pause, Mute, Volume etc.) except power aborts the above mechanism, i.e., the computer don’t poweroff after recording. Power management is turned back on by simply pressing the power button remote again.
    Before switching off after a timer, an adjustable countdown is shown by progress bar, that can be stopped.
    Is there a timer recording without any user activity occurs (eg. at night / user absent), the system will shut down without notice message after the recording was done and set next wakeup. Before doing this an email is optional delivered to the user.
    If power button is pressed and there are no upcoming/soon schedules required, the system shuts down immediately, however, timers are set.

The power button on the unit shows the normal behavior, i.e. the device switches off, timers are not set.

"Soon" fitting timers are calculated from:
ACPI: Recording Time < boot time + shutdown time + countdown time -> see screenshot
NVRAM: <11 minutes

Inside the package is a wrapper script (shutdown.sh) that needs some special settings as python itself cannot have root privileges. This is necessary for setting the system clock and shutdown operations.

Therefore: YOU MUST read the README and follow the instructions whitin the package, because there's a lot to be configured (user rights, remote.xml, etc.). Just take a look inside the zipfile.

Actions are logged into pvrmanager.log:
~ /.xbmc/temp/script.program.pvrmanager/pvrmanager.log or
~./kodi/temp/script.program.pvrmanager/pvrmanager.log

After all, this is my first addon. It would be grateful to inform me about errors, issues or other informations. Be free to contact me in this forum or PM me.

_BJ1

____________________________________________________________________

Release 0.2.4 from 11.11.14
- Ready for Helix (Kodi)
- polish translation
- revised README as PDF (for better understanding) - take a look into the zip

Release 0.2.2 from 20.06.14
- Addon is compatible now with OpenELEC without modifications on source code.

Release 0.2.0 from 06.06.14
- complete software redesign/refactoring. PVRManager has now a more object orientated behaviour and is ready for future enhancements.
- Mail notifications use an optional encryption (SSL/TLS/STARTTLS) now required from several providers.
- As there are some important settings has changed, PLEASE RESET ALL SETTINGS TO DEFAULT AND ADAPT NEW THEN.

Release 0.1.8 from 29.08.13
- check of active network connections implemented. Handle with care, it's possible that xbmc will never shut down anymore in some setups.

Release 0.1.7 from 28.08.13

- allow multiple connection attempts if TVHeadend isn't responding at first time (e.g. tvheadend isn't startet yet or later while system started up). Amount of attempts is configurable.

Release 0.1.6 from 09.08.13
- some minor bugfixes and improvements
- New: add an option to wait for multiple postprocessing scripts or commands (e.g. Comskip or Markad) after a recording or poweroff before shutdown the system.

Bugfix in 0.1.5 from 27.09.12
- If users creating a manual timer in XBMC an forgot to name the recording, the status.xml of tvheadend is incomplete. The script fails on reading some properties of the xml-file and in this case it crashed. This has been fixed. Download the fixed script from the link above as usual.

Release 0.1.5 from 08.04.12
- Since the range of EPG-Informations on some tv-services isn't long enough to serve the automatic recorder of tvheadend for a longer time, I've implemented a periodically wakeup in an interval between from "off" (inactive) to about 7 days. This is usefull for updating the EPG-data. See screenshots.

Release 0.1.4 from 24.01.12
- PVRManager optionally send mail if an automatic recording is scheduled successful and there wasn't any user activity (absent, sleeping, far from home)

Release 0.1.2 from 10.10.11

- Bug fixes, code cleaning, improved debug messages
- Error handling if TVHeadend is crashed, Typos in the README

Initial Release Oct. 2011

Installation: Copy zip to a directory where XBMC has access. Then: System -> Addons -> Install from zip file -> select location

Next steps for configuration you'll find in the README in this package.
(This post was last modified: 2014-11-12 09:12 by _BJ1.)
find quote
ronnylov Offline
Junior Member
Posts: 12
Joined: Nov 2009
Reputation: 0
Post: #2
This is exactly what I need!
I will try it on my htpc rebuild and see how it works.

Thank You!
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #3
I try to use your addon. I have media PC based on ASUS M3N78-EM mainboard. I have problem with PC wake up.
This is the log:
2011-12-20 20:05:32.106721: PVR Manager: next recording in 68 minutes
2011-12-20 20:05:32.106919: PVR Manager: service driven by User
2011-12-20 20:05:32.129694: PVR Manager: Wakeup by ACPI at 2011-12-20 21:13:32.$
2011-12-20 20:05:32.129857: PVR Manager: Instruct the system to shut down
2011-12-20 20:05:34.217110: PVR Manager: service finished
2011-12-20 20:08:20.377772: PVR Manager: next recording in 65 minutes
2011-12-20 20:08:20.389005: PVR Manager: service driven by User
2011-12-20 20:08:20.448837: PVR Manager: no PIDFile, system powered on first ti$
2011-12-20 20:08:20.449872: PVR Manager: service finished
And the time and hwclock:
rtc_time : 20:10:28
rtc_date : 2011-12-20
alrm_time : 20:13:32
alrm_date : 2011-12-20
alarm_IRQ : no
alrm_pending : no
update IRQ enabled : no
periodic IRQ enabled : no
periodic IRQ frequency : 1024
max user IRQ frequency : 64
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : yes
BCD : yes
DST_enable : no
periodic_freq : 1024
batt_status : okay
root@Mediapc:/# date
2011. dec. 20., kedd, 20.10.32 CET
root@Mediapc:/# date -u
2011. dec. 20., kedd, 19.10.35 UTC
root@Mediapc:/#

The IRQ not set and the alarm time less than I need.

I try this small script:
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date -d "2011-12-20 21:13:32" +%s` > /sys/class/rtc/rtc0/wakealarm
cat /sys/class/rtc/rtc0/wakealarm
Nothing good:
rtc_time : 20:14:01
rtc_date : 2011-12-20
alrm_time : 20:18:52
alrm_date : 2011-12-20
alarm_IRQ : no

After I try this:
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date -u -d "2011-12-20 21:13:32" +%s` > /sys/class/rtc/rtc0/wakealarm
cat /sys/class/rtc/rtc0/wakealarm

root@Mediapc:~# ./wake_test
1324415612

And the rtc settings are good:
rtc_time : 20:16:01
rtc_date : 2011-12-20
alrm_time : 21:13:32
alrm_date : 2011-12-20
alarm_IRQ : yes
alrm_pending : no

Are there any problem with UTC or local time? I'm not a programmer, and sorry for my english.

Can you help me?
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #4
Yes, you have to set your system to UTC. Is the system powered on with the 'good settings' (wake_test)?

_BJ1

To tell your Ubuntu system that the hardware clock is set to UTC:

1. edit /etc/default/rcS
2. add or change the following section

# Set UTC=yes if your hardware clock is set to UTC (GMT)
UTC=yes
(This post was last modified: 2011-12-21 13:38 by _BJ1.)
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #5
_BJ1 Wrote:Yes, you have to set your system to UTC. Is the system powered on with the 'good settings' (wake_test)?

_BJ1

To tell your Ubuntu system that the hardware clock is set to UTC:

1. edit /etc/default/rcS
2. add or change the following section

# Set UTC=yes if your hardware clock is set to UTC (GMT)
UTC=yes

Yes. The system started properly.
I set it before this log: UTC= yes, but it does not solve.
Before this try, I change the rtc clock to UTC clock. It does not help. It works only with -u parameter.
The BIOS time is UTC.
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #6
Ok. Will try to find a solution

_BJ1
(This post was last modified: 2011-12-21 18:34 by _BJ1.)
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #7
Same output as yours:

xbmc@Echnaton:/$ date
Wed Dec 21 17:53:23 CET 2011
xbmc@Echnaton:/$ date -u
Wed Dec 21 16:53:29 UTC 2011
xbmc@Echnaton:/$

But for me it works...

_BJ1

EDIT: Goto : ~/.xbmc/addons/script.program.pvrmanager/resources/lib

and edit the shutdown.sh

Change: echo $2 > /sys/class/rtc/rtc0/wakealarm
to: echo `date -ud @$2` > /sys/class/rtc/rtc0/wakealarm

Hope this works.
(This post was last modified: 2011-12-21 19:24 by _BJ1.)
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #8
Wow, needed help but no feedback. So I'm trapped in the dark...

_BJ1
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #9
_BJ1 Wrote:Wow, needed help but no feedback. So I'm trapped in the dark...

_BJ1
Wait a minute! I have no time every day to do my hobby.Nod
I change shutdown.sh as you said, but it does not work. I can't shutdown system at all. I changed it back.
After I comment the last line in shutdown.sh. In this way I trying it without really shutdown.
I change the rtc time with "hwclock --localtime" command to localtime. After this the rtc accept the date and time and wake up system. Now, I have one success record. Unfortunately it didn't switch off after the record. I don't understand exactly what was the really solution. I wait some other success records. I think very important the relationship of RTC, local time, BIOS time, UTC.
Thank you for your help!
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #10
fecus Wrote:Unfortunately it didn't switch off after the record. I don't understand exactly what was the really solution. I wait some other success records. I think very important the relationship of RTC, local time, BIOS time, UTC.
Thank you for your help!

Thanks for information. I don't know why it didn't switch off after record. Perhaps a remote key pressing whilest recording? Look into log (pvrmanager.log)
around the poweroff-time...

_BJ1
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #11
The life isn't easy. The ubuntu update files. I never do it again. New xbmc.bin arrived. Now, the xbmc display error with shutdown.sh.:

12:21:18 T:2980039536 ERROR: Error Contents: ('invalid syntax', ('/home/fecus/.xbmc/addons/script.program.pvrmanager/resources/lib/shutdown.sh', 2, 7, 'sleep 2\n'))
12:21:18 T:2980039536 ERROR: SyntaxError: ('invalid syntax', ('/home/fecus/.xbmc/addons/script.program.pvrmanager/resources/lib/shutdown.sh', 2, 7, 'sleep 2\n'))

It doesn't finish the power down.
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #12
It fails on the very first instruction into the shutdown.sh. Are executable rights, owner and group changed for the shutdown.sh? Also, looks the first line like:

#! /bin/sh

?

Merry Christmas.

_BJ1
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #13
_BJ1 Wrote:It fails on the very first instruction into the shutdown.sh. Are executable rights, owner and group changed for the shutdown.sh? Also, looks the first line like:

#! /bin/sh

?

Merry Christmas.

_BJ1

I reinstall, and re-set the rights. Nothing work.
Is it a python interpreter problem?
find quote
_BJ1 Offline
Senior Member
Posts: 174
Joined: Apr 2010
Reputation: 0
Location: Germany
Post: #14
fecus Wrote:Is it a python interpreter problem?

The shutdown.sh is an usual shellscript. Who is the user running xbmc? Maybe there are permissions.

_BJ1
(This post was last modified: 2011-12-26 00:30 by _BJ1.)
find quote
fecus Offline
Junior Member
Posts: 7
Joined: Dec 2011
Reputation: 0
Post: #15
_BJ1 Wrote:The shutdown.sh is an usual shellscript. Who is the user running xbmc? Maybe there are permissions.

_BJ1
It has 3 user : mythtv, fecus, hts
Before upgrade I added the xbmc to autorun programs and clear mythTV frontend. (This was the Mythbuntu install, originally)
I set the rights - as you wrote - for fecus, and everithing work.
After upgrade something change.
In remote.xml:
<power>XBMC.RunScript(script.program.pvrmanager)</power>

visudo:
### XBMC specific configuration ###

# XBMC
Cmnd_Alias PVR_CMDS = /home/fecus/.xbmc/addons/script.program.pvrmanager/resources/lib/shutdown.sh
fecus ALL=NOPASSWD: PVR_CMDS # XBMC

Rights of default.py:
owner: fecus
group: fecus
100755

Rights of shutdown.sh:
owner: fecus
group: fecus
100755

Rights of xbmc.bin:
owner: root
group: root
100755

I don't have more idea.No
I'm sorry for this disturbing and Merry Christmas!
find quote
Post Reply