Page 1 of 3

NetHome with EventGhost

Posted: Mon Jan 12, 2015 6:35 am
by heggholmen
Is there any support with EventGhost? My need: I want my Sonos to start playing a spesific playlist when a particular lamp is "ON".

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 8:13 am
by Nasty76
Nethome can execute sh commands or with perl you can sent TCP or udp messages can you tell how you activate that sonos play?

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 11:01 am
by krambriw
I might be guessing but I think that 'heggholmen' has found out that there is a plugin for Sonos available in EventGhost. If this is correctly understood, he is looking for methods how to generate events in EventGhost from NetHome to trigger actions for his Sonos system.

One way that could be used I have described here:
viewtopic.php?f=5&t=11#p47

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 12:28 pm
by Nasty76
ok i can try look some ideas that eventghost trigger at later today.

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 3:46 pm
by krambriw
@nasty76

First, let 'heggholmen' work & read a bit...and better define his wishes

;)

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 7:17 pm
by heggholmen
Hi guys :)

Yes - there is already a working plugin for Sonos in EventGhost - so the description from krambriw is 100% correct.
Earlier I used SwitchKing, but i experienced very bad respond using SwitchKing when I had motiondetectors that should trigger lamps. With NetHome this works so much better:):)

Your solution krambriw, should fit my need also. Would you share a step by step guide (if it's much work, just give me some hints, and I'll try:) ) - and your python script? :)

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 9:59 pm
by krambriw
Okay, I hope you run NetHome in a RaspberryPi (RPi) since the description will be based on that assumption.

1) You have a working RPi with NetHome installed & functioning

2) Now install Mosquitto, follow this instruction, http://mosquitto.org/2013/01/mosquitto- ... epository/ or simply issue the following commands from a putty session

Code: Select all

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
apt-get update
apt-get install mosquitto
3) Now you have to copy two files to your /home/pi/ folder in the RPi:
- mosquitto.py
- MQTTevents.py
Since this forum is not allowing attachments, I have provided them for download from here:http://sto.hopto.org/Under%20constructi ... enNetHome/

4) Fix so that the python script starts at boot, in a putty session, type crontab -e, add this as the last line

Code: Select all

@reboot python /home/pi/MQTTevents.py &
5) Reboot your RPi

6) After reboot, from a putty session, type 'ps aux' and check that the script is running and that you see in the list of processes that mosquitto is also running

7) Now is time to move to EventGhost

8) Install MQTT Client plugin, configure a client action to connect to your RPi (ip =????, port=1883, topic = /nethomeserver )

9) Execute MQTT Client action (run with green icon button) to connect to the Mosquitto broker and soon you should start to see events from NetHome coming into EventGhost log

10) Once you have reached here, we will discuss how to use the events for your Sonos control

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 10:17 pm
by Nasty76
oh you look handling that good , good I m total noob with event ghost , but do you guys know lets say we know what sonos want to start faforite song list. so we make example perl script example runmusic.pl
now we put there some perl code which sent sonos start command.
now we can execute that pl script via nethome example scene item and there you select exec function now we give only script path and allways when scene activate that run perl script too , I use this lot and that is handy to make something outside nethome.
here is example how I read onewire temp via raspi gpio pin and sent them upd to nethome , I have nethome item ds1820 temp plugin which I code my self , but generic upm thermometer work too. there is my perl script.

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;

my  $device = "10-0008028fd655";


    my $ret = 9999; # default to return 9999 (fail)

    my $sensordata = `cat /sys/bus/w1/devices/$device/w1_slave 2>&1`;
#    print "Read: $sensordata";


   if(index($sensordata, 'YES') != -1) {
      #fix for negative temps from http://habrahabr.ru/post/163575/
      $sensordata =~ /t=(\D*\d+)/i;
      #$sensor_temp =~ /t=(\d+)/i;
      $sensordata = (($1/1000));
      $ret = $sensordata*1000;
#sent tcp packet nethome
my $sock = IO::Socket::INET->new(
    Proto    => 'udp',
    PeerPort => 8005,
    PeerAddr => '127.0.0.1',
) or die "Could not create socket: $!\n";

print $sock "event,UPM_Message,Direction,In,UPM.DeviceCode,2,UPM.HouseCode,1,UPM.Primary,$ret,UPM.Secon$


   } else {

   }

Re: NetHome with EventGhost

Posted: Mon Jan 12, 2015 10:36 pm
by krambriw
but do you guys know lets say we know what sonos want to start
There are many, many ways to send a message to EventGhost from "outside". There are plugins supporting listening for incoming events on UDP, TCP, HTTP and many more I do not even remember now. I just mentioned MQTT because I like using a message broker...but I have also used the others from time to time

Re: NetHome with EventGhost

Posted: Tue Jan 13, 2015 6:27 am
by heggholmen
Thanks a lot krambriw!! I'm running Windows - but that's my concern:) I'll give it a try - if not I have to find my RPi, I know it's somewhere:)