ShellyPro1 Einbinden

Begonnen von th0nix, 10 Juli 2022, 20:42:48

Vorheriges Thema - Nächstes Thema

th0nix

Hallo zusammen,

hat jemand ein ShellyPro1 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.

Hermann

#1
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
Schöne Grüße aus dem Münsterland
PI3+ Fritzbox , Homematic , FS20 , 1Wire , Shelly , EspXXXX , Duofern

th0nix

Dachte ich im ersten Moment auch. Jedoch haben die Pro eine ganz andere MQTT Syntax. Daher geht leider das Shelly 1 Template nicht.

Beta-User

Für die einkanaligen "2. Gen" könnte evtl. zumindest mal als Basistemplate shellyPlus_1 (oder die pm-Variante davon)  passen.

Ansonsten wäre etwas mehr "Input" hilfreich...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

th0nix

#4
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.

Beta-User

 :) 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)...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

th0nix

Als Totaler Template Newbee - meinst du das deletereading -q DEVICE (?!associatedWith|IODev).* ? Einen "normalen" Shelly habe ich nämlich zur hand  ;)

Beta-User

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).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

th0nix

@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

Beta-User

...das ist auch ein alter Stand...

(Vermutlich habe ich da aber auch was miss-interpretiert, das ist ziemlich ausgefeilt mit einem verzögerten "get").
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

th0nix

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 ?

Beta-User

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...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files