Checking Dreambox state

Moderator: leecollings

D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Checking Dreambox state

Post by D'rMorris »

Guys,

I'm extending my bedtime event by checking the states of various devices, since I don't want the lights to go off in the middle of a movie. Now, checking the state of XBMC is easy by using this addon. This addon triggers a virtual switch in Domoticz called XBMC and this state is checked in my "bedtime" event.

Besides XBMC, we also have a Dreambox. I've done some research on how to check whether the Dreambox is on and I've come up with the following:
Via wget -N http://USER:[email protected]/web/powerstate or curl http://USER:[email protected]/web/powerstate I am able to generate an XML file with the current status of the box, for example:

<?xml version="1.0" encoding="UTF-8"?>
<e2powerstate>
<e2instandby> true </e2instandby>
</e2powerstate>

Now, using

Code: Select all

find powerstate | xargs grep 'false' -sl
I am able to search for the words "true" or "false" in the directory and then it gives back the filename "powerstate" when the word occurs.

2 problems:
- How do I write this in a lua script so that it triggers my virtual switch "Dreambox"
- Is there a better way of doing this instead of using 1 command to create a file and another to search for files with "true" or "false" in them? Maybe I can interact with the http://USER:[email protected]/web/powerstate directly and grab the standby status directly in lua? Or maybe via a XML parser like luaxml ?

Thanks!
User avatar
Mince Inside
Posts: 20
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Scotland
Contact:

Re: Checking Dreambox state

Post by Mince Inside »

Do you have access to a shell on your dreambox? I'd have a bash/shell script on the dreambox to switch the state of the virtual switch in Domotixz

M
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors
User avatar
Mince Inside
Posts: 20
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Scotland
Contact:

Re: Checking Dreambox state

Post by Mince Inside »

Just had a quick Google and the 800 can have sshd running
Complete side issue, it also has a built in Modem which would be clever to link with your alarm system to phone your mobile from home if it's going off! :)
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Yeah, that would be cool to implement! Do you have any ideas on what to put in the bash script on the dreambox?
Yesterday, I looked at http://viremo.eludi.net/LuaXML/, which offers putting XML values in LUA tables so that I can re-use it. My idea was to fill tables with info from my Dreamboxes, my XBMC etc. This is better than multiple single connections from and to systems. I like to keep stuff together, otherwise you'll get lost quickly. So, 1 LUA on the Domoticz server which checks my other devices like my dreamboxes, XBMC, etc and stores the values in a table which can be read in the same LUA.
User avatar
Mince Inside
Posts: 20
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Scotland
Contact:

Re: Checking Dreambox state

Post by Mince Inside »

Something along the lines of

Code: Select all

DreamboxStatus=`curl http://USER:[email protected]/web/powerstate | grep e2instandby | awk -F" " '{print $2}'`

if [ "$DreamboxStatus" = "true" ]
blah blah blah
You would use a curl command to update the Dreambox Status switch in Domoticz

Dont know enough about the kit in question but personally I would have a dig around on the Dreambox for startup and shutdown scripts and just inject the curl command to update the Domoticz switch status.

M
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Checking Dreambox state

Post by Derik »

Should this works with all enigma2 satbox?

What image are you using?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Actually, it runs on all Linux boxes. So also the VU for example. I'm running a Gemini image on one box and OpenPLI on another.

Thanks a lot Mince, I'll give your suggestion a try tonight or tomorrow!
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Mince,

I used a different approach, but thanks anyway for your input ;) .

Below my code, this is how it works:

- First, a curl is used to retrieve an XML file
- Next, this XML file is processed with xmlstarlet (installable with apt-get install xmlstarlet)
xmlstarlet takes the content of the first XML tag, which is e2instandby. This xml tag can have the value true or false.
- after I retrieve the on / off status (e2standby = true = off, e2standby = false = on), I send a JSON command to Domoticz to trigger a virtual switch

There are better ways I guess, but this works 100%. I'll convert this to LUA now, so that it is run automatically by Domoticz.

Next I want to check whether I can do a JSON call to Domoticz straight from the Dreamboxes, avoiding the constant polling of the devices and my Domoticz device logs not to fill up.

Any remarks, just shoot!

Code: Select all

#!/bin/bash

curl http://USER:[email protected]/web/powerstate > /home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_living.xml
DreamboxLivingStatus=`xmlstarlet sel -t -m '//e2instandby' -v . -n </home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_living.xml`

if [ $DreamboxLivingStatus = "true" ]
then
curl 'http://USER:[email protected]:PORT/json.htm?type=command&param=switchlight&idx=46&switchcmd=Off&level=0'
    echo "$DreamboxLivingStatus"
    echo Dreambox Living is in standby

elif [ $DreamboxLivingStatus = "false" ]
then
curl 'http://USER:[email protected]:PORT/json.htm?type=command&param=switchlight&idx=46&switchcmd=On&level=0'
    echo "$DreamboxLivingStatus"
    echo Dreambox Living is not in standby

else
 echo Dreambox Living not found

rm -r /home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_living.xml
fi

curl http://USER:[email protected]/web/powerstate > /home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_bedroom.xml
DreamboxBedroomStatus=`xmlstarlet sel -t -m '//e2instandby' -v . -n </home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_bedroom.xml`

if [ $DreamboxBedroomStatus = "true" ]
then
curl 'http://USER:[email protected]:PORT/json.htm?type=command&param=switchlight&idx=51&switchcmd=Off&level=0'
    echo "$DreamboxBedroomStatus"
    echo Dreambox Bedroom is in standby

elif [ $DreamboxBedroomStatus = "false" ]
then
curl 'http://USER:[email protected]:PORT/json.htm?type=command&param=switchlight&idx=51&switchcmd=On&level=0'
    echo "$DreamboxBedroomStatus"
    echo Dreambox Bedroom is not in standby

else
 echo Dreambox Bedroom not found

rm -r /home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_living.xml
rm -r /home/xbian/domoticz/scripts/dreambox/powerstate_dreambox_bedroom.xml
fi
User avatar
Mince Inside
Posts: 20
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Scotland
Contact:

Re: Checking Dreambox state

Post by Mince Inside »

Why not leave it as a bash script and run it in cron? What automation benefit do you get from putting a load on Domoticz/LUA that I'm missing?

Agree with the next stage of firing the curl command from the Dreambox.

As you are overwriting your xml every time with > and not appending with >> I'd not bother with the rm so you always have a tiny file hanging around for diagnostics.

M
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

M,

Reason behind putting it in LUA is that I can use the devices_changed option (i.e. only doing something when the status of the dreambox changes). Now, I run it in cron every 3 mins, but 95% of the time I poll the status of the dreamboxes, their status is unchanged. Besides that, I like to have everything centralised, avoiding situations where I change something in LUA and break something running in cron.

I tried running the shell script from LUA using the os.command function (so only calling the script from LUA, not the complete script in LUA), but that completely crashes my Domoticz. So for now I left it in cron.
Works perfectly, but I'd like it to be better ;).

Now that I think about it...when I append the XML instead of overwriting, I could check whether there is a status status change between the last poll and the one before that and only sending a JSON to Domoticz when there actually was a change.
Anyway, pushing from the Dreambox would be better than polling it constantly. Not that it requires much netwerk / CPU, but it's not quite efficient ;).
Tuxxie
Posts: 1
Joined: Saturday 31 August 2013 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Checking Dreambox state

Post by Tuxxie »

Hi

You can also run the shell script (in a cronjob) on the dreambox and check the contents of "/proc/stb/lcd/oled_brightness" be. At my Dreambox this file returns '25' when in standby and '102' when actived (e.g. tuned to a TV channel). Example code below:

Code: Select all

if [[ `cat /proc/stb/lcd/oled_brightness` -gt 25 ]]; then
    echo "dreambox on" 
else
    echo "dreambox standby" 
done
In this case it does a simple echo. However, you can do anything there. It must be possible to set a switch in Domoticz based on this. You can also save the state to a file and compare it with the actual state the next time the script runs. This allows you to detect a status change and only flip the switch in that condition.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Tuxxie wrote:
In this case it does a simple echo. However, you can do anything there. It must be possible to set a switch in Domoticz based on this. You can also save the state to a file and compare it with the actual state the next time the script runs. This allows you to detect a status change and only flip the switch in that condition.
Thanks for the tip Tux! I installed cURL via ipkg on the box and indeed it triggers a switch :) .

I'm still thinking about a better process though. There are several ways to accomplish a status trigger in Domoticz, I however only want to do this when the box is switched on / standby via the remote. So I'll have to figure out what code is being run when going in to / coming out of standby so that I can send cURL requests only then. Now the box is pushing it's status every 5 mins (or it's polled every 5 mins from the rasp) while the box is only used 5% of the day.
When I find this, I'll let you know!

Edit: I'm gonna play with the scripts in /usr/lib/enigma2/python/Screens, specifically the Standby.py (which is converted to the Standby.pyo at reboot, so edit the *.py files).
This way, I can call a script when the box is entering / leaving standby and only updating Domoticz when the box actually switches powerstates.
Last edited by D'rMorris on Thursday 22 May 2014 12:24, edited 1 time in total.
User avatar
Mince Inside
Posts: 20
Joined: Wednesday 02 April 2014 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Scotland
Contact:

Re: Checking Dreambox state

Post by Mince Inside »

I dont' know this kit at all but when it's in standby can you still ssh into it? Running either top or ps -ef may help pin point what is being run during standby toggle.

M
Domoticz V2.2259
Raspberry Pi (B) with PiFace
RFXtrx433 USB
LighwaveRF relays, dimmer bulbs and light switches
Siemens On/Off 13A adaptors
Marmitek MS13E Motion (and Dusk) sensors
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

M,

Thanks for your input. I've found what I'm looking for in the standby.py (and yes, you can SSH into the box when in standby, the box is always-on so to say).
When entering / leaving standby it runs the standby python script and I'm gonna insert a curl in there :).

Now, onto my Popcorn Hours to achieve the same!
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Just a quick how-to for people wanting to get their Dreambox state in Domoticz:

What I did was create two bash scripts:

enigma_enter_standby.sh

Code: Select all

#!/bin/bash
curl 'http://user:pwd@IPADDRESS:PORT/json.htm?type=command&param=switchlight&idx=XX&switchcmd=Off&level=0'
enigma_leave_standby.sh

Code: Select all

#!/bin/bash
curl 'http://user:pwd@IPADDRESS:PORT/json.htm?type=command&param=switchlight&idx=XX&switchcmd=On&level=0'
Then in the directory /usr/lib/enigma2/python/Screens, there is a script called Standby.py. In this script, I added (made bold what I added):
class Standby(Screen):
def Power(self):
print "leave standby"
import os;
os.system("sh /etc/enigma2/enigma_leave_standby.sh");


if Cbputils.gFindFile("/usr/bin/enigma_leave_standby.sh"):
Cbputils.gSystem("/usr/bin/enigma_leave_standby.sh")

then, a little further down:
def __init__(self, session):
Screen.__init__(self, session)
self.avswitch = AVSwitch()

print "enter standby"
import os;
os.system("sh /etc/enigma2/enigma_enter_standby.sh");


if Cbputils.gFindFile("/usr/bin/enigma_enter_idle.sh"):

This way, when switching the Dreambox, a virtual switch is updated in Domoticz. I use this virtual switch to control lighting etc.

By the way, my Dreambox didn't have curl installed, but you can install it easily with:
- ipkg update
- ipkg install curl

In the directory /usr/lib/enigma2/python/Screens are all the scripts that the Dreambox uses, so you could even program different things (when you change the channel for example ;)).
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Checking Dreambox state

Post by Morcegolas »

Thanks For dream box Script, gonna try it today!

Nice work! Any updates for it or new scripts for dreamboxs?

Thanks a lot! ;)
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Checking Dreambox state

Post by Morcegolas »

D'rMorris wrote: ...
Then in the directory /usr/lib/enigma2/python/Screens, there is a script called Standby.py. In this script, I added (made bold what I added):
---
I have Standby.pyo :/ can't edit that on vi, Using Dreambox 7020HD with Openatv 4.1.

Hope you can help me.
Thanks.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

the .pyo files are the ones that are compiled into .py during boot (as far as I understood).
If you do (in terminal / shell): find / -name Standby.py, do you get any results back?
I'm not familiar with Openatv, I'm running OpenPLI (but I guess the underlying kernel is similar).
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Checking Dreambox state

Post by Morcegolas »

ImageUploadedByTapatalk1412604157.758278.jpg
ImageUploadedByTapatalk1412604157.758278.jpg (135.84 KiB) Viewed 9899 times
None :/
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Checking Dreambox state

Post by D'rMorris »

Bummer :-(. Can you make a screenshot of all your files in /usr/lib/enigma2/python/Screens?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest