FHEM Forum

FHEM - Hausautomations-Systeme => MQTT => Thema gestartet von: th0nix am 10 Juli 2022, 20:42:48

Titel: ShellyPro1 Einbinden
Beitrag von: th0nix am 10 Juli 2022, 20:42:48
Hallo zusammen,

hat jemand ein ShellyPro1 https://shelly.cloud/shelly-pro-smart-home-automation-solution/#Pro-1 (https://shelly.cloud/shelly-pro-smart-home-automation-solution/#Pro-1) im FHEM bereits integriert ?
Habe leider kein Standard Template gefunden welche ich zuweisen könnte.

Danke schon mal für eure Hilfe.
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: Hermann am 10 Juli 2022, 23:40:10
Hallo

Ich habe zwar z.Zt. kein Shelly Pro im einsatz.
Ich denke aber das das Template von Shelly 1 gehen sollte, mehr Funktionen hat der Pro ja auch nicht.

Einfach mal probieren

mfg.
Hermann
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: th0nix am 10 Juli 2022, 23:42:13
Dachte ich im ersten Moment auch. Jedoch haben die Pro eine ganz andere MQTT Syntax. Daher geht leider das Shelly 1 Template nicht.
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: Beta-User am 11 Juli 2022, 07:13:59
Für die einkanaligen "2. Gen" könnte evtl. zumindest mal als Basistemplate shellyPlus_1 (https://svn.fhem.de/trac/browser/trunk/fhem/FHEM/lib/AttrTemplate/mqtt2.template#L3427) (oder die pm-Variante davon)  passen.

Ansonsten wäre etwas mehr "Input (https://forum.fhem.de/index.php/topic,112327.0.html)" hilfreich...
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: th0nix am 12 Juli 2022, 00:21:37
Hi, Des shellyPlus_1 war eine gute Basis. Danke für den Tipp. Habe noch ein wenig was angepasst:

# Shelly Pro 1 using original firmware.
name:shellyPro1
filter:TYPE=MQTT2_DEVICE
desc:Early version of a base template for Shelly Pro 1 devices (names with "pro", without power measurement).<br><br>For correct use activate the <b>Generic status update over MQTT</b> in the Shelly Pro 1 under the Networks / MQTT Configuration.<br>to reduce the mqtt messages <i>RPC status notifications over MQTT</i> can be disabled.<br>NOTE: Please wait some seconds to allow Shelly device to complete reboot after assigning the Template
par:DEV_TPC;Configured MQTT prefix on the Shelly;{ AttrVal('DEVICE','devicetopic',AttrVal('DEVICE','readingList','')) =~ m<(shellies/[^/]+|shellyp(lus|ro4pm)[^/:_]{4,}+)> ? $1 : undef }
par:CALLSPEECHRECOGN;Set this to 0 to not set any speech recogn. related attributes;{ 1 }
order:A_20
deletereading -q DEVICE (?!associatedWith|IODev).*
attr DEVICE devicetopic DEV_TPC
attr DEVICE setList\
  toggle:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Toggle","params": {"id":0}}\
  off:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":false}}\
  on:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":true}}\
  on-for-timer $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":true,"toggle_after":$EVTPART1}}\
  off-for-timer $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":false,"toggle_after":$EVTPART1}}\
  x_update:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Shelly.Update","params": {"stage":"stable"}}\
  x_reboot:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Shelly.Reboot"}\
  x_eco:true,false $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Sys.SetConfig","params": {"config": {"device": {"eco_mode": $EVTPART1}}}}
attr DEVICE readingList $\DEVICETOPIC/online:.* online\
  $\DEVICETOPIC/events/rpc:.* { json2nameValue($EVENT,'',$JSONMAP) }\
  $\DEVICETOPIC/status/mqtt:.* { json2nameValue($EVENT, 'mqtt_', $JSONMAP) }\
  $\DEVICETOPIC/status/sys:.* { json2nameValue($EVENT, 'sys_', $JSONMAP) }\
  $\DEVICETOPIC/status/switch_0:.* { $EVENT =~ s/"output":true/"state":"on"/g; $EVENT =~ s/"output":false/"state":"off"/g; json2nameValue($EVENT, 'switch_', $JSONMAP) }\
  $\DEVICETOPIC/status/cloud:.* {}\
  $\DEVICETOPIC/rpc:.* {}
attr DEVICE devStateIcon {my $onl = ReadingsVal($name,'online','false') eq 'false'?'10px-kreis-rot':'10px-kreis-gruen'; $onl = FW_makeImage($onl); my $light = FW_makeImage(ReadingsVal($name,'state','off')); my $temp = ReadingsVal($name,'temperature','n/a'); my $ip = ReadingsVal($name,'ip','none'); my $reb = ReadingsVal($name,'sys_restart_required','false') eq 'true'?'<a href="/fhem?cmd.dummy=set '.$name.' x_reboot&XHR=1"> ... Notwendigen Reboot durchführen</a>':''; qq(<a href="http://$ip" target="_blank">${onl}</a><a href="/fhem?cmd.dummy=set $name toggle&XHR=1">${light}</a>$reb<div>Temp: $temp °C</div>)}
attr DEVICE jsonMap switch_state:state switch_temperature_tC:temperature switch_temperature_tF:0 params_sys_restart_required:0
attr DEVICE setStateList on off toggle on-for-timer off-for-timer
attr DEVICE model shellypro1
setreading DEVICE attrTemplateVersion 20220711
set DEVICE x_reboot
option:{ CALLSPEECHRECOGN }
set DEVICE attrTemplate speechcontrol_type_switch



Wer es testen will - einfach in die Datei FHEM/lib/AttrTemplate/mqtt2.template kopieren und neu starten

//13.07.22 Habe die MQTT Quelle von RPC status notifications over MQTT auf Generic status update over MQTT geändert. So reicht ein Datensatz welcher verarbeitet werden muss + es wird die Temperatur mitgegeben.
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: Beta-User am 12 Juli 2022, 15:29:48
 :) irgendwie sieht das zumindest betr. das "detach" konsistenter aus als die aktuelle attrTemplate-Fassung ::) ...

Falls du auch einen "normalen" hast: Kannst du das mal checken, ob das Sinn macht? Es wird da nämlich auf demselben Pfad gesendet und empfangen, und das ist erfahrungsgemäß Unfug (was mir leider nicht rechtzeitig aufgefallen ist)...
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: th0nix am 13 Juli 2022, 23:30:19
Als Totaler Template Newbee - meinst du das deletereading -q DEVICE (?!associatedWith|IODev).* ? Einen "normalen" Shelly habe ich nämlich zur hand  ;)
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: Beta-User am 14 Juli 2022, 10:33:09
Zitat von: th0nix am 13 Juli 2022, 23:30:19
Als Totaler Template Newbee - meinst du das deletereading -q DEVICE (?!associatedWith|IODev).* ? Einen "normalen" Shelly habe ich nämlich zur hand  ;)
Nein. Im "normalen" shellyPlus_1-attrTemplate findet sich in der setList u.A. diese Zeile:
in_mode:toggle,flip,detached {fhem("sleep 0.2; get $NAME in_mode"); my $val = $EVTPART1 ne 'toggle' ? $EVTPART1 : ReadingsVal($NAME,'in_mode','flip') eq 'flip' ? 'detached':'flip'; qq($\DEVICETOPIC/rpc {"id":1,"src":"fhem2shelly","method":"Switch.SetConfig","params": {"id":0, "config": {"in_mode": "$val"}}})}\

Und in der readingList u.A. diese Zeile:  $\DEVICETOPIC/rpc:.* { json2nameValue($EVENT, 'req_', $JSONMAP, 'in_mode')}\
Das wirkt mit etwas Nachdenken auf mich, als würde die M2D-Instanz also "links" was versenden, das "rechts" ausgewertet wird. Wenn das korrekt ist, ist es Mist...
Es kann sein, dass man das mit MQTT2_SERVER gar nicht merkt, aber sobald ein externer Server ins Spiel kommt, sollte der Effekt da sein.

Neben einem "normalen Shelly _der 2. Generation_" bräuchtest du also vermutlich auch einen MQTT2_CLIENT (der kann via localhost auf den M2-Server zeigen).
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: th0nix am 18 Juli 2022, 22:35:57
@Beta-User

habe leider nur die erste Generation ohne Plus.
Wollte es mir auch mal in dem Template anschauen. Gefunden habe ich es jedoch bei mir irgendwie nicht. Da sieht der shellyPlus_1 so aus...


###########################################
# SHELLY plus section
#
# shelly devices using the V2 MQTT API https://shelly-api-docs.shelly.cloud/gen2/Overview/RPCChannels#mqtt
# Shelly Plus 1 using original firmware.
name:shellyPlus_1
filter:TYPE=MQTT2_DEVICE
desc:Early version of a base template for second generation shelly devices (names with "plus", without power measurement). NOTE: requires to activate generic status update in firmware settings (if not available: reset device to factory defaults).<br>NOTE: Please wait some seconds to allow Shelly device to complete reboot.
par:DEV_TPC;Shelly name in the topic;{ AttrVal('DEVICE','devicetopic',AttrVal('DEVICE','readingList','')) =~ m<(shellies/[^/]+|shellyp(lus|ro4pm)[^/:_]{4,}+)> ? $1 : undef }
par:CALLSPEECHRECOGN;Set this to 0 to not set any speech recogn. related attributes;{ 1 }
order:A_20
par:ICON;ICON as set, defaults to message_socket;{ AttrVal('DEVICE','icon','message_socket') }
deletereading -q DEVICE (?!associatedWith|IODev).*
attr DEVICE icon ICON
attr DEVICE devicetopic DEV_TPC
attr DEVICE setList\
  toggle:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Toggle","params": {"id":0}}\
  off:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":false}}\
  on:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":true}}\
  on-for-timer $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":true,"toggle_after":$EVTPART1}}\
  off-for-timer $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Switch.Set","params": {"id":0,"on":false,"toggle_after":$EVTPART1}}\
  x_update:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Shelly.Update","params": {"stage":"stable"}}\
  x_reboot:noArg $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Shelly.Reboot"}\
  x_eco:true,false $\DEVICETOPIC/rpc {"id":0,"src":"fhem2shelly","method":"Sys.SetConfig","params": {"config": {"device": {"eco_mode": $EVTPART1}}}}
attr DEVICE readingList $\DEVICETOPIC/online:.* online\
  $\DEVICETOPIC/events/rpc:.* { json2nameValue($EVENT,'',$JSONMAP) }\
  $\DEVICETOPIC/status/mqtt:.* { json2nameValue($EVENT, 'mqtt_', $JSONMAP) }\
  $\DEVICETOPIC/status/sys:.* { json2nameValue($EVENT, 'sys_', $JSONMAP) }\
  $\DEVICETOPIC/status/switch_0:.* { $EVENT =~ s/"output":true/"state":"on"/g; $EVENT =~ s/"output":false/"state":"off"/g; json2nameValue($EVENT, 'switch_', $JSONMAP) }\
  $\DEVICETOPIC/status/cloud:.* {}\
  $\DEVICETOPIC/rpc:.* {}\
  fhem2shelly/rpc:.* {}
attr DEVICE devStateIcon {my $onl = ReadingsVal($name,'online','false') eq 'false'?'10px-kreis-rot':'10px-kreis-gruen'; $onl = FW_makeImage($onl); my $light = FW_makeImage(ReadingsVal($name,'state','off')); my $temp = ReadingsVal($name,'temperature','-100'); my $ip = ReadingsVal($name,'ip','none'); my $reb = ReadingsVal($name,'sys_restart_required','false') eq 'true'?'<a href="/fhem?cmd.dummy=set '.$name.' x_reboot&XHR=1"> ... Notwendigen Reboot durchführen</a>':''; qq(<a href="http://$ip" target="_blank">${onl}</a><a href="/fhem?cmd.dummy=set $name toggle&XHR=1">${light}</a>$reb<div>Temp: $temp °C</div>)}
attr DEVICE jsonMap switch_state:state switch_temperature_tC:temperature switch_temperature_tF:0 params_wifi_sta_ip:ip
attr DEVICE setStateList on off toggle on-for-timer off-for-timer
attr DEVICE webCmd :
attr DEVICE model shellyPlus_1
setreading DEVICE attrTemplateVersion 20220118
set DEVICE x_reboot
option:{ CALLSPEECHRECOGN }
set DEVICE attrTemplate speechcontrol_type_switch
Titel: Antw:ShellyPro1 Einbinden
Beitrag von: Beta-User am 19 Juli 2022, 16:26:20
...das ist auch ein alter Stand...

(Vermutlich habe ich da aber auch was miss-interpretiert, das ist ziemlich ausgefeilt mit einem verzögerten "get").
Titel: Aw: ShellyPro1 Einbinden
Beitrag von: th0nix am 06 April 2023, 00:23:26
bei einer Neuinstallation bin ich wieder auf dieses Thema gestoßen.
Macht es vielleicht Sinn den Code Schnipsel oben mit ins repo rein zu nehmen so das man es nicht immer manuell rein-bauen muss ?
Titel: Aw: ShellyPro1 Einbinden
Beitrag von: Beta-User am 06 April 2023, 11:04:28
Bin grade etwas verloren. Kannst du das bitte so spezifizieren, dass ich nicht den ganzen Thread nochmal durchdenken muss?

Ein diff oder sonst klare "das wäre zu ändern"-Hinweise wären hilfreich. Falls ich Fragen dazu gestellt hatte, bitte auch dazu eine Antwort, sonst kommt ggf. nochmal dieselbe Frage...