chatBot (vordefinierte Dialoge) für Telegram

Begonnen von igami, 27 März 2016, 17:17:32

Vorheriges Thema - Nächstes Thema

Esjay

Danke für die schnelle und ausführliche Antwort!

Also mit den von dir genannten Paketen,geht das abspeichern der SVG Datein als PNG komplett automatisch von statten ja?

Das Sysmon Modul hab ich sogar bereits definiert.Hab die Readings wohl nur nicht wahr genommen. :o

Das Wort "Überwachung" wahr wohl ein bisschen irreführend!
Ich schalte über pilight meine Funksteckdosen und habe dementsprechend eine Steckdose mit "define Schlafzimemr pilight_switch kaku_switch  19864566 0" formuliert, die mir auch als state "on" und "off" liefert.

Also müsste doch mein Code dann so aussehen!?

if($msgText eq "/StStatus"){
my $temptext = "";
if(ReadingsVal('Schlafzimmer','state','0') eq "off"){
$temptext = "Die Steckdose ist aus";
}elsif(ReadingsVal('Schlafzimmer','state','0') eq "on"){
$temptext = "Die Steckdose ist an";
}
fhem_bot_response(
$temptext,
"/hauptmenue",
);
}


Bin gerade noch auf der Arbeit,deswegen kann ich nicht direkt testen.

Ich hoffe das kommt alles nicht all zu "der hat ja gar keine Ahnung" rüber.

Grüße

tiroso

Wenn dein Device Schlafzimmer heisst ist es korrekt. Aber ich glaube es heisst bei dir Schlafzimmer_pilight_switch.

Ja wenn dein FHEM unter /opt/fhem/ läuft werden dort auch die PNGs abgelegt.

Ach ist ja kein Problem. Dafür ist es ja da um drüber zu reden. ;)

andre07

Hallo tiroso

Komme mit deinen sicherheitseinstellungen nicht ganz klar
Im telgram_bot fhem habe ich das ergänzt
userattr   -FhemBot_ReceiveRestrictedPeer 1 , -FhemBot_ReceiveCustomPeer 22042539X
In deinen code das dies ergänzt
my $msgPeerId = "22042539X";
my $TelegramBot_Device = "andre_telegram";

wobei 22042539X die  msgPeerId von meinen  handy contact ist und andre_telegram mein bot in fhem.
Funktioniert so leider nicht kannst du mir vielleicht auf die Sprünge helfen was da flasch ist.

RoBra81

Hallo,

da ich auch mal Dialoge auf diese Art gebaut habe und nun aber ein neues Modul entdeckt habe, mit welche ich meine Dialoge umgebaut und erweitert habe, möchte ich hier zur Info mal darauf verweisen - vielleicht ist das ja was für den einen oder anderen...

https://forum.fhem.de/index.php/topic,54863.0.html

Ronny

networker

hallo andre07

Bist du dir mit den userattr sicher?
userattr   -FhemBot_ReceiveRestrictedPeer 1 , -FhemBot_ReceiveCustomPeer 22042539X

Im Code fragt er die userattr ohne den führenden "-" ab.

lG, Michael

andre07

Ich habe das so im Telegram_bot definiert wie muß es denn genau
aussehen
so dann ???
userattr  FhemBot_ReceiveRestrictedPeer 1 , FhemBot_ReceiveCustomPeer 22042539X
kannst du mir helfen

Andre

marvin78

Wie wäre es denn, mal die Doku von FHEM zu userattr zu konsultieren?

userattr erhält durch Leerzeichen getrennt die neuen Attribute:

attr DEV userattr FhemBot_ReceiveRestrictedPeer FhemBot_ReceiveCustomPeer

Dann bekommt das Device die neuen Attribute und diese setzt du dann, wie beschrieben.

Bitte ein wenig mit den FHEM Grundlagen beschäftigen.

andre07

#22
Hallo marvin

Soweit war ich schon hatte FhemBot_ReceiveRestrictedPeer den wert 1 gegeben und FhemBot_ReceiveCustomPeer 22042539X
was aber so anscheinend falsch ist weil der chatbot nicht reagiert
rnals:
   DEF        206056671:AAH__ifJ9WnkHqupXzKYmXb87rYw6rHdxxx
   FAILS      0
   NAME       telegram_andre
   NR         625
   OLD_POLLING 14
   POLLING    14
   SNAME      telegram_andre
   STATE      Polling
   TYPE       TelegramBot
   Token      206056671:AAH__ifJ9WnkHqupXzKYmXb87rYw6rHdxxx
   UPDATER    0
   URL        https://api.telegram.org/bot206056671:AAH__ifJ9WnkHqupXzKYmXb87rYw6rHdxxx/
   WAIT       0
   me         206056671:andre:@andreg8_bot
   Aliascmds:
     /lichtan   set RemotePI cmd set Schlafzimmer_Nachttisch on
     /lichtaus  set RemotePI cmd set Schlafzimmer_Nachttisch off
     /speakvolume setreading telegram_andre currentSpeakVolume
     /stromverbrauch {plotAsPng("SVG_FileLog_stromsensor.haus_4")}
     /tv        set RemotePI cmd set Schlafzimmer_Fernseher on
     /wohnzimmer setreading telegram_andre currentSpeakPlayer Sonos_Schlafzimmer
   Contacts:
     220425399  220425399:gustav:@adolfo
   Hu_do_params:
     header     agent: TelegramBot/1.0

User-Agent: TelegramBot/1.0

Accept: application/json

Accept-Charset: utf-8
     hideurl    1
     method     GET
     timeout    30
     url
   Hu_upd_params:
     FD         106
     NAME
     addr       https://api.telegram.org:443
     buf
     code       200
     displayurl <hidden>
     header     agent: TelegramBot/1.0

User-Agent: TelegramBot/1.0

Accept: application/json

Accept-Charset: utf-8
     hideurl    1
     host       api.telegram.org
     httpheader HTTP/1.1 200 OK

Server: nginx/1.10.0

Date: Wed, 06 Jul 2016 16:10:59 GMT

Content-Type: application/json

Content-Length: 23

Connection: close

Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: GET, POST, OPTIONS

Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection

Strict-Transport-Security: max-age=31536000; includeSubdomains
     hu_blocking 0
     hu_filecount 3
     isPolling  update
     loglevel   4
     method     GET
     offset     0
     path       /bot206056671:AAH__ifJ9WnkHqupXzKYmXb87rYw6rHdCZU/getUpdates?offset=0&limit=5&timeout=120
     protocol   https
     redirects  0
     timeout    245
     url        https://api.telegram.org/bot206056671:AAH__ifJ9WnkHqupXzKYmXb87rYw6rHdxxx/getUpdates?offset=0&limit=5&timeout=120
     Hash:
     Sslargs:
   Readings:
     2016-06-05 14:20:25   Contacts        22042539x:gustav:@adolfo
     2016-07-06 18:08:28   PollingErrCount 3
     2016-07-06 18:08:28   PollingLastError NonBlockingGet timed out on read from <hidden> after 245s
     2016-06-06 19:21:44   currentSpeakPlayer Sonos_Schlafzimmer
     2016-07-04 12:24:47   msgChat
     2016-07-04 12:24:47   msgFileId
     2016-07-04 12:24:47   msgId           1241
     2016-07-04 12:24:47   msgPeer         gustav
     2016-07-04 12:24:47   msgPeerId       22042539x
     2016-07-04 12:24:47   msgText         /start
     2016-07-04 12:24:47   prevMsgChat
     2016-07-04 12:24:47   prevMsgFileId
     2016-07-04 12:24:47   prevMsgId       1240
     2016-07-04 12:24:47   prevMsgPeer     gustav
     2016-07-04 12:24:47   prevMsgPeerId   22042539x
     2016-07-04 12:24:47   prevMsgText     /start
     2016-07-06 06:16:38   sentMsgId       1318
     2016-07-06 06:16:38   sentMsgResult   SUCCESS
Attributes:
   FhemBot_ReceiveCustomPeer 22042539x
   FhemBot_ReceiveRestrictedPeer 1
   defaultPeer @adolfo
   favorites  /lichtan=set RemotePI cmd set Schlafzimmer_Nachttisch on;/tv=?set RemotePI cmd set Schlafzimmer_Fernseher on;set RemotePI cmd set Schlafzimmer_Fernseher off;/wohnzimmer=setreading telegram_andre currentSpeakPlayer Sonos_Schlafzimmer ; /speakvolume=setreading telegram_andre currentSpeakVolume;/stromverbrauch={plotAsPng("SVG_FileLog_stromsensor.haus_4")};/lichtaus=set RemotePI cmd set Schlafzimmer_Nachttisch off
   maxRetries 3
   pollingTimeout 120
   room       Status
   userattr   FhemBot_ReceiveRestrictedPeer FhemBot_ReceiveCustomPeer


Habs rausgefunden
FhemBot_ReceiveRestrictedPeer wert 0 und es geht :)
aber warum steht dann im code das

# Bitte dran denken im TelegramBot Device die
# userattr:
# -FhemBot_ReceiveRestrictedPeer   (1/1)
# -FhemBot_ReceiveCustomPeer      (Custom Peers)
# zu setzen.

tiroso

Hallöchen,

Andre sorry hatte vergessen zu antworten...mache es jetzt hier.

Ich habe diese zwei UserAttr mit dazu genommen um auf verschiedene Peerszu reagieren.

FhemBot_ReceiveRestrictedPeer -> Wenn gesetzt werden nur Peers akzeptiert die im Attr cmdRestrictedPeer stehen. Das ist ein Attr vom TelegramMessenger selber. Wenn FhemBot_ReceiveRestrictedPeer = 0 werden die Peers im UserAttr FhemBot_ReceiveCustomPeer nur akzeptiert.

Ich sehe das ist was verwirrend ... Tut mir Leid:(


:D
Hatte versucht mein unsortierten Code zu sortieren und Userfreundlicher zu gestalten und dann sowas

andre07

Danke noch jetzt läuft es ja ein Problem hätte ich noch den Versand von plots
der will bei mir nicht so richtig, bekomme  nur  Grafiken mit "no logdevice" zugesandt
definiert ist das so bei mir if($msgText eq "/heizungsplot"){
fhem_bot_svgresponse(
["SVG_Filelog.Thermostat.WZ_Clima_1.svg","SVG Plot Wohnzimmer"],
["Bad_Heizung_Clima_1.svg","SVG Plot Badezimmer"],
["SVG_FileLog_Dach_Heizung_Clima_1.svg","SVG Plot Dachboden"],
                                ["SVG_FileLog_stromsensor.haus_4.svg","Stromverbrauch"],
);

Die gleichnamigen plots befinden sich bei mir /opt/fhem/www/glot/SVG_Filelog.Thermostat.WZ_Clima_1.gplot......
Dies hier geht definiert bei favorites /stromverbrauch={plotAsPng("SVG_FileLog_stromsensor.haus_4")}
plotAsPng funktioniert also
Andre

tiroso


andre07

#26
Check ich heute abend
Von der Arbeit gehts ja auch
das steht im log

2016.07.08 11:44:18 3: SVG_Filelog.Thermostat.WZ_Clima_1.svg: space is not allowed in  definition: Corresponding FileLog definition:
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_Filelog.Thermostat.WZ_Clima_1.svg: space is not allowed in  definition: define ememlog FileLog /var/log/fhem/emem-%Y.log emem:power.*
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
2016.07.08 11:44:18 1: No Logdevice
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: Bad_Heizung_Clima_1.svg: space is not allowed in  definition: Display the power reported by the EM1010
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 778.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: Bad_Heizung_Clima_1.svg: space is not allowed in  definition: Corresponding FileLog definition:
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: Bad_Heizung_Clima_1.svg: space is not allowed in  definition: define ememlog FileLog /var/log/fhem/emem-%Y.log emem:power.*
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
2016.07.08 11:44:18 1: No Logdevice
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_Dach_Heizung_Clima_1.svg: space is not allowed in  definition: Display the power reported by the EM1010
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 778.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_Dach_Heizung_Clima_1.svg: space is not allowed in  definition: Corresponding FileLog definition:
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_Dach_Heizung_Clima_1.svg: space is not allowed in  definition: define ememlog FileLog /var/log/fhem/emem-%Y.log emem:power.*
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
2016.07.08 11:44:18 1: No Logdevice
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_stromsensor.haus_4.svg: space is not allowed in  definition: Display the power reported by the EM1010
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 778.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_stromsensor.haus_4.svg: space is not allowed in  definition: Corresponding FileLog definition:
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in concatenation (.) or string at ./FHEM/98_SVG.pm line 763.
2016.07.08 11:44:18 3: SVG_FileLog_stromsensor.haus_4.svg: space is not allowed in  definition: define ememlog FileLog /var/log/fhem/emem-%Y.log emem:power.*
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $src in hash element at ./FHEM/98_SVG.pm line 775.
[Fri Jul  8 11:44:18 2016] fhem.pl: Use of uninitialized value $ldType in string eq at ./FHEM/98_SVG.pm line 751.

ripper

Hallo,

ich teste jetzt schon einige Stunden mit dem Code von tiroso. Danke erst mal dafür!!

Allerdings habe ich ein hoffentlich kleines Problem an dem ich nicht weiter komme. Ich kann zwar mit dem Bot chatten und er gibt mir z.B. auch mein Menü aus. Allerdings werden keine Befehle ausgeführt.
Befehle für die Jalousien schauen bei mir so aus:
if($msgText eq "/AlleAuf"){
fhem_bot_fhem_cmd(
"set .*rollo.* auf",
);
fhem_bot_response(
"Alle Jalousien werden geschlossen.\n/jalousie\n/hauptmenue",
);
}
if($msgText eq "/AlleZu"){
fhem_bot_fhem_cmd(
"set .*rollo.* zu",
);
fhem_bot_response(
"Alle Jalousien werden geöffnet.\n/jalousie\n/hauptmenue",
);
}
if($msgText eq "/SchlafzimmerAnkippen"){
fhem_bot_fhem_cmd(
"set Sc_rollo pct 2",
);
fhem_bot_response(
"Schlafzimmer Jalousie wurde gekippt",
);
}


Wenn ich mein "99_myChat_Utils.pm" speichere bekomme ich folgenden Fehler:

Bareword "jarvisAThome" not allowed while "strict subs" in use at ./FHEM/99_myChat_Utils.pm line 69.

Wobei jarvisAThome mein Bot ist.
Ich steh hier gerade echt auf dem Schlauch. Kann mir vielleicht jemand einen "Schupser" oder einen Tipp geben??
Wenn noch weitere Infos benötigt werden liefere ich die natürlich gerne nach.

Vielen Dank schon mal :-)

Maista

Moin ripper

Was steht denn in der Zeile 69 deines Moduls?

Grussig Gerd

ripper



oh..ja klar..

my $TelegramBot_Device = jarvisAThome;

an der stelle wird das TelegramBot Device hinterlegt. Deswegen versteh ichs auch nicht. Wenn ich meinem Bot etwas schicke, bekomme ich z.B. mein Menü zurück und kann dann auf mein Jalousie Menü drücken. Auch meine eigene Auswahl, AlleAuf, AlleZu und SchlafzimmerAnkippen bekomme ich im Chat angezeigt. Nur der Befehl wird nicht abgesetzt.
Hab mal noch was anderes getestet:
Im Code von toriso steht:

if($msgText eq "/sonosstop"){
fhem_bot_fhem_cmd(
"set Sonos StopAll",
);
fhem_bot_response(
"Alle Sonos Boxen wurden gestoppt.\n/hauptmenue",
);
}


wenn ich dass drinnen lasse und meinem Bot /sonosstop schicke bzw. anklicke dann bekomme ich einen log Eintrag dass ich Sonos erst definieren muss. Wenn ich meine rollo befehle direkt über die fhem Eingabezeile ausführe dann bewegen sich die Jalousien.