-
-
Notifications
You must be signed in to change notification settings - Fork 13
FHEM examples
Till Steinbach edited this page Jan 24, 2022
·
13 revisions
define mymqttbroker MQTT2_CLIENT mymqttbroker:1883
attr mymqttbroker clientId fhem
attr mymqttbroker username user
afterwards set the password
define MyCar MQTT2_DEVICE
attr MyCar IODev mymqttbroker
attr MyCar devicetopic weconnect/0/vehicles/AAABBBCCCDD123456
attr MyCar icon car
attr MyCar room Cars
Now map the topics you want to use to the MQTT topics: e.g.:
attr MyCar readingList $DEVICETOPIC/model:.* model\
$DEVICETOPIC/domains/access/accessStatus/overallStatus:.* accessStatus
attr MyCar readingList $DEVICETOPIC/([0-9a-zA-Z_]+):.* { $TOPIC =~ m,/([0-9a-zA-Z_]+)$,; { "${1}"=>$EVENT }}\
$DEVICETOPIC/domains/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z_]+):.* { $TOPIC =~ m,domains/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z_]+),; { "${2}_${3}"=>$EVENT }}\
$DEVICETOPIC/domains/access/([0-9a-zA-Z]+)/doors/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)State:.* { $TOPIC =~ m,domains/access/([0-9a-zA-Z]+)/doors/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)State,; { "${1}_doors_${2}_${3}State"=>$EVENT }}\
$DEVICETOPIC/domains/access/([0-9a-zA-Z]+)/windows/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)State:.* { $TOPIC =~ m,domains/access/([0-9a-zA-Z]+)/windows/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)State,; { "${1}_windows_${2}_${3}State"=>$EVENT }}\
$DEVICETOPIC/domains/fuelStatus/rangeStatus/([0-9a-zA-Z]+)Engine/([0-9a-zA-Z_]+):.* { $TOPIC =~ m,domains/fuelStatus/rangeStatus/([0-9a-zA-Z]+)Engine/([0-9a-zA-Z_]+),; { "rangeStatus_${1}Engine_${2}"=>$EVENT }}\
$DEVICETOPIC/domains/readiness/readinessStatus/([0-9a-zA-Z]+)/([0-9a-zA-Z_]+):.* { $TOPIC =~ m,domains/readiness/readinessStatus/([0-9a-zA-Z]+)/([0-9a-zA-Z_]+),; { "readinessStatus_${1}_${2}"=>$EVENT }}\
$DEVICETOPIC/pictures/statusWithBadge:.* { WriteFile("www/images/$NAME-status-badge.png",$EVENT);;}
To use commands, you have to map those to writeable topics:
attr MyCar setList climatisation:start,stop $DEVICETOPIC/controls/climatisation_writetopic $EVTPART1\
charging:start,stop $DEVICETOPIC/controls/charging_writetopic $EVTPART1\
maxChargeCurrentAC_current:maximum,reduced $DEVICETOPIC/domains/charging/chargingSettings/maxChargeCurrentAC_writetopic $EVTPART1\
autoUnlockPlugWhenCharged:true,false $DEVICETOPIC/domains/charging/chargingSettings/autoUnlockPlugWhenCharged_writetopic $EVTPART1\
targetSOC:slider,0,10,100 $DEVICETOPIC/domains/charging/chargingSettings/targetSOC_pct_writetopic $EVTPART1\
climatisationWithoutExternalPower:true,false $DEVICETOPIC/domains/climatisation/climatisationSettings/climatisationWithoutExternalPower_writetopic $EVTPART1\
climatizationAtUnlock:true,false $DEVICETOPIC/domains/climatisation/climatisationSettings/climatizationAtUnlock_writetopic $EVTPART1\
windowHeatingEnabled:true,false $DEVICETOPIC/domains/climatisation/climatisationSettings/windowHeatingEnabled_writetopic $EVTPART1\
zoneFrontLeftEnabled:true,false $DEVICETOPIC/domains/climatisation/climatisationSettings/zoneFrontLeftEnabled_writetopic $EVTPART1\
zoneFrontRightEnabled:true,false $DEVICETOPIC/domains/climatisation/climatisationSettings/zoneFrontRightEnabled_writetopic $EVTPART1\
If you want to also display the cars status add:
attr MyCar readingList $DEVICETOPIC/model:.* model\
$DEVICETOPIC/domains/access/accessStatus/overallStatus:.* accessStatus\
$DEVICETOPIC/pictures/statusWithBadge:.* { WriteFile("www/images/$NAME-status-badge.png",$EVENT);;;;}
attr MyCar devStateIcon { '<img src="fhem/images/' . $name . '-status-badge.png" style="max-width:256px;; max-height:256px;;">' }
For chargers you can use a definition like:
define Kattjahren MQTT2_DEVICE
setuuid Kattjahren 61eec384-f33f-0ed0-2b0a-8e1b3823a664edf9
attr Kattjahren IODev mosquitto
attr Kattjahren devicetopic weconnect/0/chargingStations/699511dd-023e-46fb-945a-a3fd74b67ce8
attr Kattjahren icon hue_filled_plug
attr Kattjahren readingList $DEVICETOPIC/([a-zA-Z]+):.* { $TOPIC =~ m,/([a-zA-Z]+)$,;; { "${1}"=>$EVENT }}\
$DEVICETOPIC/chargingSpots/([0-9]+)/([0-9a-zA-Z_]+):.* { $TOPIC =~ m,chargingSpots/([0-9]+)/([0-9a-zA-Z]+),;; { "spot${1}_${2}"=>$EVENT }}
attr Kattjahren room Chargers
Remember that you need to set e.g. --chargingLocation 50.123456 10.123456 --chargingLocationRadius=500
to receive chargers in the output