alexa-fhem: amazon alexa smart home skill für fhem

Begonnen von justme1968, 05 November 2016, 23:21:32

Vorheriges Thema - Nächstes Thema

MadMax-FHEM

Zitat von: freak4all am 04 November 2018, 12:33:33
Erstmal muss aber alexa-fhem sich allein starten ohne putty.

Erst schauen welches System: Wheezy, Jessie, Stretch, ...

Bzw. wie werden deine Services aktuell gestartet: systemd / initd

Dann für eine davon entscheiden, weil im alexa-fhem Wiki (zumindest war das mal so) sind beide Startarten ein wenig durcheinander...

Bei initd das dort irgendwo verlinkte Startscript (anpassen an eigene "Bedürfnisse" nicht vergessen: User/Pfade/...) und zum Kontrollieren aus fhem heraus (falls gewünscht) noch die 2 Dummy und das DOIF.

Bei Start mittels systemd ein systemd Startscript erstellen (sollten einige zu finden sein, ebenfalls anpassen User/Pfade etc.).
Bei Start durch systemd geht die Kontrolle/Steuerung aus fhem heraus NICHT mit den 2 Dummy und DOIF!!

Dafür gibt es aber ein Modul zur Steuerung von Diensten aus fhem: https://forum.fhem.de/index.php/topic,79952.msg719659.html#msg719659

Gruß und viel Spaß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

Wasserwerk33

Hoffe ihr reist mir gleich nicht den Kopf ab. Aber ich bekomme es einfach nicht hin.
Habe es schon mehrmals von neuem versucht. Aber immer wieder der selbe Fehler.
Hab mal Screenshorts gemacht wie ich vorgehe. Und wo ich die codes her habe. Hoffentlich weiß jemand was ich falsch gemacht habe.

freak4all

Du musst in aws Lambda Alexa smart home als Auslöser nehmen, nicht Alexa skills Kit!

Gesendet von meinem HTC U11 mit Tapatalk
PI3B FHEM 5.8, 2xSonoff mit Tasmota, Xiaomi Vacuum Roborock S50, Alexa (Echo Plus), VU+ Ultimo 4K, VU+ Zero, Karatelight, 7580, 7490, Easymouse V2, Qnap TS-212....

Wasserwerk33

Okay habe ich geändert.
Kommt trotzdem die selbe fehlermeldung. Oder muss ich nun index.js in die lambda.js jetzt erst ersetzen?


const PORT=3000;
const HOST='mein.host.name';


// entry
exports.handler = function(event, context, callback) {

  console.log(`EVENT: ${event}`);
  console.log(`CONTEXT: ${context}`);
 
  var post_data = JSON.stringify(event);
 
  var options = {
    hostname: HOST,
    port: PORT,
    //family: 6,
    //path: '/',
    method: 'POST',
    rejectUnauthorized: false, // accept self-signed
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(post_data)
    }
  };

  var request = require('https').request(options, (result) => {
    console.log(`STATUS: ${result.statusCode}`);
    console.log(`HEADERS: ${JSON.stringify(result.headers)}`);
    result.setEncoding('utf8');
    var body = '';
    result.on('data', (chunk) => body += chunk);
    result.on('end', () => {
      console.log(`BODY: ${JSON.stringify(body)}`);
      callback(null, JSON.parse(body) );
      return;
    });
  });

  request.on('error', (e) => {
    console.log(`problem with request: ${e.message}`);
    callback(null, createError(ERROR_TARGET_OFFLINE) );
    return;
  });

  request.write(post_data);
  request.end();

  return;
 
}// exports.handler


Ist es richtig das ich den ganzen quellcode rauslösche und dann den vom index dort einfüge?

Also im Endeffekt so??
const PORT=3000;
const HOST='mein.host.name';


// entry
exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!')
    };
    return response;
};
  return;
 
}// exports.handler


Ja leider brauch ich ein wenig hilfe da die videos und die Wiki seite leider nicht mehr passen.

freak4all

Du musst alles in der Index.js löschen und den kompletten Inhalt der lambda.js einfügen. Unter host musst du dann deine IP deines Internetanschlusses bzw dein dyndns eintragen. Port 3000 bleibt ja bestehen.

Ot: dein Nickname gefällt mir, bin selbst Wassermeister [emoji28]

Gesendet von meinem HTC U11 mit Tapatalk

PI3B FHEM 5.8, 2xSonoff mit Tasmota, Xiaomi Vacuum Roborock S50, Alexa (Echo Plus), VU+ Ultimo 4K, VU+ Zero, Karatelight, 7580, 7490, Easymouse V2, Qnap TS-212....

Wasserwerk33

Danke werde dann erstmal weiter machen und dann mich nochmal melden wenn ich hänge.
Ne bin kein Wassermeister, nur am Wochenende  ;) ist meine Straße wo ich wohne  ;)

Danke erstmal für die hilfe

dadoc

Hallo zusammen,
für viele - wie auch für mich - scheint es ja ein no-go zu sein, dass mit der hier beschriebenen Alexa-Einbindung der Router ins Internet "geöffnet" werden muss.
In einem anderen Projekt, das ich verfolge  - LMS bzw. Squeezeplayer - scheint sich die Problematik der Alexa-Anbindung ähnlich darzustellen: https://github.com/declension/squeeze-alexa/blob/master/docs/HOWTO.md Dort hat jemand einen Skill in Entwicklung, den man wahlweise über einen SSL-Tunnel (Router muss eingehende Port-Anfragen mappen) oder über eine MQT-Bridge (ohne Öffnung/Port Mapping) anbinden kann: https://github.com/declension/squeeze-alexa/blob/master/docs/MQTT.md .
Für fhem gibt es ja auch bereits einiges an MQT-Aktivitäten, z.B. die Generic MQT Bridge als Modul: https://forum.fhem.de/index.php/topic,81418.0.html. Da ich die Abkürzung heute zum ersten Mal gehört habe und zudem nur ziemlich rudimentäre Programmierkenntnisse besitze, werfe ich das einfach mal in die Runde mit der Frage, ob das evtl. auch eine Option für die Alexa-fhem-Anbindung sein könnte?
Grüße
Martin
Standort 1: FS20 mit CUL und FHEM auf Raspi. HM-Komponenten (Heizung, Rollladen, Schalter). HM IP über Raspimatic (testweise)
Standort 2: Homematic (Wired) über CCU2 und PocketHome HD
3 x Raspi3 mit piCorePlayer/Kodi für Multiroom Audio (+ Tablets/iPeng/iPods

amenomade

Und was ist genau der Unterschied, was offene Ports angeht?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

dadoc

Soweit ich das verstehe, muss ich für den MQT-Tunnel kein port forwarding betreiben und mein Netzwerk so zu indest nicht auf diesem Weg dem Internet öffnen. Aber wie gesagt, ich verstehe auf Anhieb bestenfalls die Hälfte von dem, was ich dazu lese. Darum habe ich es ja Euch für die Füße geworfen ;)
Standort 1: FS20 mit CUL und FHEM auf Raspi. HM-Komponenten (Heizung, Rollladen, Schalter). HM IP über Raspimatic (testweise)
Standort 2: Homematic (Wired) über CCU2 und PocketHome HD
3 x Raspi3 mit piCorePlayer/Kodi für Multiroom Audio (+ Tablets/iPeng/iPods

freak4all

Ich tu mich etwas schwer mit dem autostart von alexa-fhem.
Das will irgendwie nicht funktionieren bei mir.
Kann mir da bitte nochmal jemand behilflich sein?
Zitat von: MadMax-FHEM am 04 November 2018, 12:58:23
Erst schauen welches System: Wheezy, Jessie, Stretch, ...
So siehts aus bei mir:

root@raspberrypi:~# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian

Zitat von: MadMax-FHEM am 04 November 2018, 12:58:23
Bzw. wie werden deine Services aktuell gestartet: systemd / initd
wie bekomm ich das raus?

Zitat von: MadMax-FHEM am 04 November 2018, 12:58:23
Dann für eine davon entscheiden, weil im alexa-fhem Wiki (zumindest war das mal so) sind beide Startarten ein wenig durcheinander...
das ist wohl wahr!
PI3B FHEM 5.8, 2xSonoff mit Tasmota, Xiaomi Vacuum Roborock S50, Alexa (Echo Plus), VU+ Ultimo 4K, VU+ Zero, Karatelight, 7580, 7490, Easymouse V2, Qnap TS-212....

MadMax-FHEM

#3895
Was sagt:

ls -la /etc/init.d/

Und was:

ls -la /etc/systemd/system/

Jenachdem machen wir dann weiter... ;-)

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

freak4all

da kommt folgendes:
root@raspberrypi:~# ls -la /etc/init.d
total 172
drwxr-xr-x  2 root root  4096 Nov  4 21:02 .
drwxr-xr-x 88 root root  4096 Nov  4 21:07 ..
-rwxr-xr-x  1 root root  2271 Nov  4 21:05 alexa
-rw-------  1 root root 12288 Nov  3 17:11 .alexa.swp
-rwxr-xr-x  1 root root  5336 Feb  1  2016 alsa-utils
-rwxr-xr-x  1 root root  2401 Jan 23  2017 avahi-daemon
-rwxr-xr-x  1 root root  2948 Oct 24  2016 bluetooth
-rwxr-xr-x  1 root root  1232 Apr  7  2017 console-setup.sh
-rwxr-xr-x  1 root root  3049 May 19  2015 cron
-rwxr-xr-x  1 root root  2813 Jul 30  2017 dbus
-rwxr-xr-x  1 root root  1901 Sep 14  2015 dhcpcd
-rwxr-xr-x  1 root root  2198 Oct 24  2016 dphys-swapfile
-rwxr-xr-x  1 root root  6697 Apr 17  2017 fail2ban
-rwxr-xr-x  1 root root   824 Sep  5  2014 fake-hwclock
-rwxr-xr-x  1 root root  1442 Jan 16  2018 fhem
-rwxr-xr-x  1 root root  3809 Mar 22  2017 hwclock.sh
-rwxr-xr-x  1 root root  1479 May 19  2016 keyboard-setup.sh
-rwxr-xr-x  1 root root  2044 Dec 26  2016 kmod
-rwxr-xr-x  1 root root  3323 Nov  3  2016 mosquitto
-rwxr-xr-x  1 root root  4597 Sep 16  2016 networking
-rwxr-xr-x  1 root root  5658 Dec 15  2016 nfs-common
-rwxr-xr-x  1 root root  2786 Dec 18  2014 paxctld
-rwxr-xr-x  1 root root  1366 Dec 18  2016 plymouth
-rwxr-xr-x  1 root root   752 Dec 18  2016 plymouth-log
-rwxr-xr-x  1 root root  1191 Nov 22  2016 procps
-rwxr-xr-x  1 root root  1210 Jul  4  2017 raspi-config
-rwxr-xr-x  1 root root  2358 May  5  2017 rpcbind
-rwxr-xr-x  1 root root  4355 Jul 10  2014 rsync
-rwxr-xr-x  1 root root  2868 Jan 18  2017 rsyslog
-rwxr-xr-x  1 root root  4033 Jun 18  2017 ssh
-rwxr-xr-x  1 root root   731 Jun  5  2017 sudo
-rwxr-xr-x  1 root root  3217 Aug 30  2016 triggerhappy
-rwxr-xr-x  1 root root  6087 Jul  5  2017 udev
-rwxr-xr-x  1 root root  2069 Aug 29  2016 vsftpd
-rwxr-xr-x  1 root root  2757 Nov 23  2016 x11-common
root@raspberrypi:~# ^C
root@raspberrypi:~# ls -la /etc/systemd/system
total 68
drwxr-xr-x 16 root root 4096 Nov  4 21:01 .
drwxr-xr-x  5 root root 4096 Aug 26 14:01 ..
-rw-r--r--  1 root root 1551 Jul  4  2017 autologin@.service
drwxr-xr-x  2 root root 4096 Jun 13 20:19 bluetooth.target.wants
lrwxrwxrwx  1 root root   37 Nov 29  2017 dbus-org.bluez.service -> /lib/systemd/system/bluetooth.service
lrwxrwxrwx  1 root root   40 Nov 29  2017 dbus-org.freedesktop.Avahi.service -> /lib/systemd/system/avahi-daemon.service
lrwxrwxrwx  1 root root   34 Nov 29  2017 dhcpcd5.service -> /lib/systemd/system/dhcpcd.service
drwxr-xr-x  2 root root 4096 Nov 29  2017 dhcpcd.service.d
drwxr-xr-x  2 root root 4096 Nov 29  2017 getty.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 getty@tty1.service.d
drwxr-xr-x  2 root root 4096 Nov 29  2017 halt.target.wants
drwxr-xr-x  2 root root 4096 Nov  4 12:52 multi-user.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 network-online.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 poweroff.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 rc-local.service.d
drwxr-xr-x  2 root root 4096 Nov 29  2017 reboot.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 remote-fs.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 sockets.target.wants
drwxr-xr-x  2 root root 4096 Nov 29  2017 sysinit.target.wants
lrwxrwxrwx  1 root root   35 Nov 29  2017 syslog.service -> /lib/systemd/system/rsyslog.service
drwxr-xr-x  2 root root 4096 Nov 29  2017 timers.target.wants
PI3B FHEM 5.8, 2xSonoff mit Tasmota, Xiaomi Vacuum Roborock S50, Alexa (Echo Plus), VU+ Ultimo 4K, VU+ Zero, Karatelight, 7580, 7490, Easymouse V2, Qnap TS-212....

MadMax-FHEM

Ok, du hast zwar Stretch wo eigentlich systemd Standard ist...
...allerdings startet fhem wohl per initd.

Auch ein Startscript für alexa ist ja schon da...
...scheint aber wohl nicht zu tun.

Poste doch mal den Inhalt des Startscriptes:

sudo cat /etc/init.d/alexa

Bevor ich nachlese/suche: wie startest du nochmal alexa?
Also wo installiert, wo die config.json und mit welchem User...

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

freak4all

root@raspberrypi:~# sudo cat /etc/init.d/alexa
#!/bin/sh
### BEGIN INIT INFO
# Provides: alexa
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time for alexa
# Description: Enable service provided by daemon.
### END INIT INFO
export PATH=$PATH:/usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules
PID=`pidof alexa`
export ALEXAPATH="/opt/alexa-fhem"
export LOGPATH="/opt/fhem/log"
case "$1" in
start)
if ps -p $PID > /dev/null 2>&1; then
        echo "Alexa is already running"
        perl /opt/fhem/fhem.pl 7072 "setreading FHEM.Alexa.Status info Alexa is already running"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa.Status on"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa off"
else
        su - "pi" -c "cd $ALEXAPATH;./bin/alexa > $LOGPATH/alexa-`date +%Y-%m`.log 2>&1 &"
        echo "Alexa starting"
        sleep 2
        $0 status
fi
;;
stop)
if ! ps -p $PID > /dev/null 2>&1; then
        echo "Alexa is not running"
        perl /opt/fhem/fhem.pl 7072 "setreading FHEM.Alexa.Status info Alexa is not running"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa.Status off"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa off"
else
        kill $PID
        echo "Alexa closed"
        perl /opt/fhem/fhem.pl 7072 "setreading FHEM.Alexa.Status info Alexa closed"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa.Status off"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa off"
fi
;;
restart)
if ! ps -p $PID > /dev/null 2>&1; then
        $0 start
else
        $0 stop
        $0 start
fi
;;
status)
if ps -p $PID > /dev/null 2>&1; then
        echo "Alexa is running PID $PID"
        perl /opt/fhem/fhem.pl 7072 "setreading FHEM.Alexa.Status info Alexa running as PID $PID"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa.Status on"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa off"
else
        echo "Alexa is not running"
        perl /opt/fhem/fhem.pl 7072 "setreading FHEM.Alexa.Status info Alexa is not running"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa.Status off"
        perl /opt/fhem/fhem.pl 7072 "set FHEM.Alexa off"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
echo "script done"
exit 0


alexa starte ich so

root@raspberrypi:~# cd alexa-fhem
root@raspberrypi:~/alexa-fhem# ./bin/alexa
[2018-11-6 21:57:00] using /root/.alexa/config.json
[2018-11-6 21:57:00] ---
[2018-11-6 21:57:00] this is alexa-fhem 0.4.4
[2018-11-6 21:57:00] Fetching FHEM devices...
....und so weiter


denke mal der user ist root
PI3B FHEM 5.8, 2xSonoff mit Tasmota, Xiaomi Vacuum Roborock S50, Alexa (Echo Plus), VU+ Ultimo 4K, VU+ Zero, Karatelight, 7580, 7490, Easymouse V2, Qnap TS-212....

MadMax-FHEM

Ja User ist wohl laut allem was man so sieht root...

Dann wird das mit dem Script nicht klappen können:

su - "pi" -c "cd $ALEXAPATH;./bin/alexa > $LOGPATH/alexa-`date +%Y-%m`.log 2>&1 &"

denn das Script versucht als User 'pi' zu starten...

Also entweder das Script umstricken auf root...
...oder (besser) alexa als User 'pi' lauffähig bekommen...

Auch das wird wohl nicht passen (was man aber an deinen Ausgaben nur vermuten kann: root@raspberrypi:~/alexa-fhem wird wohl /root/alexa-fhem sein):

export ALEXAPATH="/opt/alexa-fhem"

Wenn du mittels:

sudo /etc/init.d/alexa start

startest müssten Fehler kommen...

Bzw. sollte/könnte auch was im Log stehen (export LOGPATH="/opt/fhem/log"):

ls /opt/fhem/log/alexa*.*

sollte zeigen wie es (oder sie) heißt/heißen...

EDIT: hast du folgendes (überhaupt) ausgeführt: sudo update-rc.d alexa defaults ?

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)