Shelly Pro 2: Anbindung mittels MQTT

Begonnen von stobor, 28 Juli 2026, 11:24:52

Vorheriges Thema - Nächstes Thema

stobor

Hallo,
wie bringe ich denn am besten einen Shelly Pro 2 zum Laufen?

Ich habe schon versucht, das Template des Shelly Pro 4pm zu verwenden, doch wenn ich den Shelly über dessen Web-Interface schalte kommt bei FHEM nichts an.
Angebunden ist der Shelly über MQTT and erzeugt über AUTOCREATE:

define shellypro2_TerrasseSued MQTT2_DEVICE shellypro2_TerrasseSued
setuuid shellypro2_TerrasseSued 6a66f6cd-f33f-2cfb-292f-2e4ed82ccbf83416
attr shellypro2_TerrasseSued 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 shellypro2_TerrasseSued devicetopic shellypro2_TerrasseSued
attr shellypro2_TerrasseSued getList in_mode:noArg in_mode $DEVICETOPIC/rpc {"id": 1,"src":"$DEVICETOPIC", "method": "Switch.GetConfig", "params": {"id": 0}}
attr shellypro2_TerrasseSued icon message_socket
attr shellypro2_TerrasseSued jsonMap switch_state:state switch_temperature_tC:temperature switch_temperature_tF:0 params_wifi_sta_ip:ip params_switch_0_temperature_tC:temperature params_switch_0_temperature_tF:0 req_result_in_mode:in_mode
attr shellypro2_TerrasseSued model shellyPlus_1
attr shellypro2_TerrasseSued 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:.* { json2nameValue($EVENT, 'req_', $JSONMAP, 'in_mode')}\
  $DEVICETOPIC/status/input_0:.* { json2nameValue($EVENT, 'input_', $JSONMAP) }\
  fhem2shelly/rpc:.* {}\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/events/rpc:.* { json2nameValue($EVENT, 'rpc_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/switch_1:.* { json2nameValue($EVENT, 'switch_1_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/switch_0:.* { json2nameValue($EVENT, 'switch_0_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/online:.* online\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/ble:.* ble\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/cloud:.* { json2nameValue($EVENT, 'cloud_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/eth:.* { json2nameValue($EVENT, 'eth_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/input_0:.* { json2nameValue($EVENT, 'input_0_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/input_1:.* { json2nameValue($EVENT, 'input_1_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/mqtt:.* { json2nameValue($EVENT, 'mqtt_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/sys:.* { json2nameValue($EVENT, 'sys_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/wifi:.* { json2nameValue($EVENT, 'wifi_', $JSONMAP) }\
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/ws:.* { json2nameValue($EVENT, 'ws_', $JSONMAP) }
attr shellypro2_TerrasseSued room MQTT,Terrasse
attr shellypro2_TerrasseSued 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}}\
  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"}}})}\
  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 shellypro2_TerrasseSued setStateList on off toggle on-for-timer off-for-timer
attr shellypro2_TerrasseSued webCmd :



Internals
CID    shellypro2_TerrasseSued
DEF    shellypro2_TerrasseSued
   
FUUID    6a66f6cd-f33f-2cfb-292f-2e4ed82ccbf83416
IODev    MQTT2
LASTInputDev    MQTT2
MQTT2_CONN    MQTT2_192.168.179.24_59748
MQTT2_MSGCNT    14
MQTT2_TIME    27.07.2026 15:13
MSGCNT    14
NAME    shellypro2_TerrasseSued
NR    1899
STATE    set_on
TYPE    MQTT2_DEVICE
eventCount    26

Readings
IODev
MQTT2
2026-07-27 15:04:43
associatedWith
shellypro2_TerrasseSued_CH2,shellypro2_TerrasseSued_CH3,shellypro2_TerrasseSued_CH4
2026-07-27 15:02:51
attrTemplateVersion
20240627
2026-07-27 15:02:53
ble
{}
2026-07-27 15:05:07
cloud_connected
false
2026-07-27 15:05:07
input_0_id
0
2026-07-27 15:05:07
input_0_state
false
2026-07-27 15:05:07
input_1_id
1
2026-07-27 15:05:07
input_1_state
false
2026-07-27 15:05:07
mqtt_connected
true
2026-07-27 15:05:07
online
true
2026-07-27 15:05:07
rpc_dst
shellypro2-TerrasseSued/events
2026-07-27 15:13:34
rpc_method
NotifyStatus
2026-07-27 15:13:34
rpc_params_cloud_connected
false
2026-07-27 15:05:07
rpc_params_input_0_id
0
2026-07-27 15:05:07
rpc_params_input_0_state
false
2026-07-27 15:05:07
rpc_params_input_1_id
1
2026-07-27 15:05:07
rpc_params_input_1_state
false
2026-07-27 15:05:07
rpc_params_mqtt_connected
true
2026-07-27 15:05:07
rpc_params_switch_0_id
0
2026-07-27 15:05:52
rpc_params_switch_0_output
false
2026-07-27 15:05:52
rpc_params_switch_0_source
WS_in
2026-07-27 15:05:52
rpc_params_switch_0_temperature_tC
34.5
2026-07-27 15:05:07
rpc_params_switch_0_temperature_tF
94.1
2026-07-27 15:05:07
rpc_params_switch_1_id
1
2026-07-27 15:13:34
rpc_params_switch_1_output
true
2026-07-27 15:05:40
rpc_params_switch_1_source
WS_in
2026-07-27 15:05:40
rpc_params_switch_1_temperature_tC
44.06
2026-07-27 15:13:34
rpc_params_switch_1_temperature_tF
111.30
2026-07-27 15:13:34
rpc_params_sys_available_updates_beta_version
2.0.0-beta3
2026-07-27 15:05:07
rpc_params_sys_available_updates_stable_version
1.7.5
2026-07-27 15:05:07
rpc_params_sys_cfg_rev
8
2026-07-27 15:05:07
rpc_params_sys_fs_free
208896
2026-07-27 15:05:07
rpc_params_sys_fs_size
524288
2026-07-27 15:05:07
rpc_params_sys_kvs_rev
0
2026-07-27 15:05:07
rpc_params_sys_mac
80F3DAC8B8A0
2026-07-27 15:05:07
rpc_params_sys_ram_free
111420
2026-07-27 15:05:07
rpc_params_sys_ram_size
260204
2026-07-27 15:05:07
rpc_params_sys_reset_reason
3
2026-07-27 15:05:07
rpc_params_sys_restart_required
false
2026-07-27 15:05:07
rpc_params_sys_schedule_rev
0
2026-07-27 15:05:07
rpc_params_sys_time
15:05
2026-07-27 15:05:07
rpc_params_sys_unixtime
1785157506
2026-07-27 15:05:07
rpc_params_sys_uptime
23287
2026-07-27 15:05:07
rpc_params_sys_webhook_rev
0
2026-07-27 15:05:07
rpc_params_ts
1785158014.19
2026-07-27 15:13:34
rpc_params_wifi_rssi
-72
2026-07-27 15:05:07
rpc_params_wifi_ssid
Quadratogramm
2026-07-27 15:05:07
rpc_params_wifi_sta_ip
192.168.179.24
2026-07-27 15:05:07
rpc_params_wifi_status
got ip
2026-07-27 15:05:07
rpc_params_ws_connected
false
2026-07-27 15:05:07
rpc_src
shellypro2-80f3dac8b8a0
2026-07-27 15:13:34
switch_0_id
0
2026-07-27 15:05:52
switch_0_output
false
2026-07-27 15:05:52
switch_0_source
WS_in
2026-07-27 15:05:52
switch_0_temperature_tC
34.6
2026-07-27 15:05:52
switch_0_temperature_tF
94.3
2026-07-27 15:05:52
switch_1_id
1
2026-07-27 15:13:34
switch_1_output
true
2026-07-27 15:13:34
switch_1_source
WS_in
2026-07-27 15:13:34
switch_1_temperature_tC
44.1
2026-07-27 15:13:34
switch_1_temperature_tF
111.3
2026-07-27 15:13:34
sys_available_updates_beta_version
2.0.0-beta3
2026-07-27 15:05:07
sys_available_updates_stable_version
1.7.5
2026-07-27 15:05:07
sys_cfg_rev
8
2026-07-27 15:05:07
sys_fs_free
208896
2026-07-27 15:05:07
sys_fs_size
524288
2026-07-27 15:05:07
sys_kvs_rev
0
2026-07-27 15:05:07
sys_mac
80F3DAC8B8A0
2026-07-27 15:05:07
sys_ram_free
110016
2026-07-27 15:05:07
sys_ram_size
260100
2026-07-27 15:05:07
sys_reset_reason
3
2026-07-27 15:05:07
sys_restart_required
false
2026-07-27 15:05:07
sys_schedule_rev
0
2026-07-27 15:05:07
sys_time
15:05
2026-07-27 15:05:07
sys_unixtime
1785157506
2026-07-27 15:05:07
sys_uptime
23287
2026-07-27 15:05:07
sys_webhook_rev
0
2026-07-27 15:05:07
wifi_rssi
-73
2026-07-27 15:05:07
wifi_ssid
Quadratogramm
2026-07-27 15:05:07
wifi_sta_ip
192.168.179.24
2026-07-27 15:05:07
wifi_status
got ip
2026-07-27 15:05:07
ws_connected
false
2026-07-27 15:05:07
x_reboot
set

Attributes
comment
Shelly Pro 2
deleteattr
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>)}
deleteattr
devicetopic
shellypro2_TerrasseSued
deleteattr
getList
in_mode:noArg in_mode $DEVICETOPIC/rpc {"id": 1,"src":"$DEVICETOPIC", "method": "Switch.GetConfig", "params": {"id": 0}}
deleteattr
icon
message_socket
deleteattr
jsonMap
switch_state:state switch_temperature_tC:temperature switch_temperature_tF:0 params_wifi_sta_ip:ip params_switch_0_temperature_tC:temperature params_switch_0_temperature_tF:0 req_result_in_mode:in_mode
deleteattr
model
shellyPlus_1
deleteattr
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:.* { json2nameValue($EVENT, 'req_', $JSONMAP, 'in_mode')}
  $DEVICETOPIC/status/input_0:.* { json2nameValue($EVENT, 'input_', $JSONMAP) }
  fhem2shelly/rpc:.* {}
shellypro2_TerrasseSued:shellypro2-TerrasseSued/online:.* online
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/ble:.* ble
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/cloud:.* { json2nameValue($EVENT, 'cloud_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/eth:.* { json2nameValue($EVENT, 'eth_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/input_0:.* { json2nameValue($EVENT, 'input_0_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/input_1:.* { json2nameValue($EVENT, 'input_1_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/mqtt:.* { json2nameValue($EVENT, 'mqtt_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/switch_0:.* { json2nameValue($EVENT, 'switch_0_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/switch_1:.* { json2nameValue($EVENT, 'switch_1_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/sys:.* { json2nameValue($EVENT, 'sys_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/wifi:.* { json2nameValue($EVENT, 'wifi_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/status/ws:.* { json2nameValue($EVENT, 'ws_', $JSONMAP) }
shellypro2_TerrasseSued:shellypro2-TerrasseSued/events/rpc:.* { json2nameValue($EVENT, 'rpc_', $JSONMAP) }
deleteattr
room
MQTT,Terrasse
deleteattr
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}}
  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"}}})}
  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}}}}
deleteattr
setStateList
on off toggle on-for-timer off-for-timer
deleteattr
webCmd
:
Intel NUC (Ubuntu 24.04.4 LTS)  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 31515 - FS20, HM(IP), MQTT, Philips HUE, ModBus

rudolfkoenig

Zitatwenn ich den Shelly über dessen Web-Interface schalte kommt bei FHEM nichts an.
Existiert das Problem auch bei einem nicht mit attrTemplate modifizierten Instanz, d.h. direkt nach autocreate?
Was ist der Typ vom IODev (MQTT2), MQTT2_SERVER oder MQTT2_CLIENT?
Welche Nachrichten empfaengt das IODev (siehe "Show MQTT Traffic" auf der Detailseite des IODevs)

Bitte in der Zukunft kein "einfaches" Copy-Paste verwenden, sondern das auf der Detailseite unten befindliche "Copy for forum.fhem.de"

Beta-User

In devicetopic dürfte der Unterstrich falsch sein => ersetzen durch einen Bindestrich.
Server: HP-elitedesk@Debian 13, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

stobor

Zitat von: Beta-User am 28 Juli 2026, 12:53:14In devicetopic dürfte der Unterstrich falsch sein => ersetzen durch einen Bindestrich.
Magic!
Vielen Dank, das scheint es gewesen zu sein.
Intel NUC (Ubuntu 24.04.4 LTS)  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 31515 - FS20, HM(IP), MQTT, Philips HUE, ModBus