mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
mqtt2.template: add sonoff_tasmota_1ch and 2ch
git-svn-id: https://svn.fhem.de/fhem/trunk@17785 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4521fd4ad8
commit
7faa3e781e
@ -51,7 +51,13 @@ MQTT2_DEVICE_Define($$)
|
||||
return "wrong syntax for $name: define <name> MQTT2_DEVICE [clientid]"
|
||||
if(int(@a));
|
||||
$hash->{DEVICETOPIC} = $name;
|
||||
$modules{MQTT2_DEVICE}{defptr}{cid}{$hash->{CID}} = $hash if($hash->{CID});
|
||||
if($hash->{CID}) {
|
||||
my $dpc = $modules{MQTT2_DEVICE}{defptr}{cid};
|
||||
if(!$dpc->{$hash->{CID}}) {
|
||||
$dpc->{$hash->{CID}} = [];
|
||||
}
|
||||
push(@{$dpc->{$hash->{CID}}},$hash);
|
||||
}
|
||||
|
||||
AssignIoPort($hash);
|
||||
return undef;
|
||||
@ -147,10 +153,9 @@ MQTT2_DEVICE_Parse($$)
|
||||
}
|
||||
return if(!$newCid);
|
||||
|
||||
my $cidHash = $modules{MQTT2_DEVICE}{defptr}{cid}{$newCid};
|
||||
my $nn = $cidHash ? $cidHash->{NAME} : "MQTT2_$newCid";
|
||||
PrioQueue_add(sub{
|
||||
return if(!$defs{$nn});
|
||||
my $cidArr = $modules{MQTT2_DEVICE}{defptr}{cid}{$newCid};
|
||||
return if(!$cidArr);
|
||||
my $add;
|
||||
if($value =~ m/^{.*}$/) {
|
||||
my $ret = json2nameValue($value);
|
||||
@ -160,14 +165,19 @@ MQTT2_DEVICE_Parse($$)
|
||||
$topic =~ m,.*/([^/]+),;
|
||||
$add = ($1 ? $1 : $topic);
|
||||
}
|
||||
my $rl = AttrVal($nn, "readingList", "");
|
||||
$rl .= "\n" if($rl);
|
||||
my $regexpCid = ($cid eq $newCid ? "$cid:" : "");
|
||||
CommandAttr(undef, "$nn readingList $rl${regexpCid}$topic:.* $add");
|
||||
|
||||
for my $ch (@{$cidArr}) {
|
||||
my $nn = $ch->{NAME};
|
||||
my $rl = AttrVal($nn, "readingList", "");
|
||||
$rl .= "\n" if($rl);
|
||||
my $regexpCid = ($cid eq $newCid ? "$cid:" : "");
|
||||
CommandAttr(undef, "$nn readingList $rl${regexpCid}$topic:.* $add");
|
||||
}
|
||||
MQTT2_DEVICE_Parse($iodev, $msg);
|
||||
}, undef);
|
||||
|
||||
return "UNDEFINED $nn MQTT2_DEVICE $newCid" if(!$cidHash);
|
||||
my $cidArr = $modules{MQTT2_DEVICE}{defptr}{cid}{$newCid};
|
||||
return "UNDEFINED MQTT2_$newCid MQTT2_DEVICE $newCid" if(!$cidArr);
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -385,7 +395,9 @@ MQTT2_DEVICE_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
MQTT2_DEVICE_delReading($arg);
|
||||
delete $modules{MQTT2_DEVICE}{defptr}{cid}{$hash->{CID}} if($hash->{CID});
|
||||
my $dpc = $modules{MQTT2_DEVICE}{defptr}{cid}{$hash->{CID}};
|
||||
my @nh = grep { $_->{NAME} != $hash->{NAME} } @{$dpc};
|
||||
$modules{MQTT2_DEVICE}{defptr}{cid}{$hash->{CID}} = \@nh;
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# perl_code returns a value for the parameter, or undef.
|
||||
# If undef, the user has to specify them (the comment is shown to the user)
|
||||
|
||||
# The zigbee2mqtt bridge device
|
||||
name:zigbee2mqtt_bridge
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
par:BRIDGENAME;name of the zigbee2mqtt bridge in the topics
|
||||
@ -17,6 +18,7 @@ attr DEVICE setList\
|
||||
devicelist:noArg zigbee2mqtt/BRIDGENAME/config/devices
|
||||
|
||||
|
||||
# A dimmable light connected via zigbee2mqtt
|
||||
name:zigbee2mqtt_bulb
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
par:NAMEINTHEBRIDGE;name of this device in the bridge;{ AttrVal("DEVICE","readingList","") =~ m,zigbee2mqtt/(.*):, ? $1 : undef }
|
||||
@ -27,7 +29,7 @@ attr DEVICE setList \
|
||||
off:noArg zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"OFF"}\
|
||||
brightness:colorpicker,BRI,0,15,255 zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"on","$EVTPART0":"$EVTPART1"}
|
||||
|
||||
|
||||
# A dimmable color light connected via zigbee2mqtt
|
||||
name:zigbee2mqtt_colorbulb
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
par:NAMEINTHEBRIDGE;name of this device in the bridge;{ AttrVal("DEVICE","readingList","") =~ m,zigbee2mqtt/(.*):, ? $1 : undef }
|
||||
@ -38,3 +40,34 @@ attr DEVICE setList \
|
||||
off:noArg zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"OFF"}\
|
||||
brightness:colorpicker,BRI,0,15,255 zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"on","$EVTPART0":"$EVTPART1"}\
|
||||
color_temp:colorpicker,CT,250,1,454 zigbee2mqtt/NAMEINTHEBRIDGE/set {"$EVTPART0":"$EVTPART1"}
|
||||
|
||||
|
||||
# Basic sonoff 1 channel device flashed with Tasmota
|
||||
name:sonoff_tasmota_1ch
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
par:MQTTNAME;Topic in "Configure MQTT", must be unique;{ AttrVal("DEVICE","readingList","") =~ m,tele/(.*)/LWT:, ? $1 : undef }
|
||||
attr DEVICE stateFormat POWER1
|
||||
attr DEVICE setList \
|
||||
off:noArg cmnd/MQTTNAME/POWER1 0\
|
||||
on:noArg cmnd/MQTTNAME/POWER1 1\
|
||||
toggle:noArg cmnd/MQTTNAME/POWER1 2
|
||||
|
||||
|
||||
# sonoff 2 channel device flashed with Tasmota.
|
||||
# NOTE: a second device will be created for the second channel
|
||||
name:sonoff_tasmota_2ch
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
par:MQTTNAME;Topic in "Configure MQTT", must be unique;{ AttrVal("DEVICE","readingList","") =~ m,tele/(.*)/LWT:, ? $1 : undef }
|
||||
attr DEVICE stateFormat POWER1
|
||||
attr DEVICE setList \
|
||||
off:noArg cmnd/MQTTNAME/POWER1 0\
|
||||
on:noArg cmnd/MQTTNAME/POWER1 1\
|
||||
toggle:noArg cmnd/MQTTNAME/POWER1 2
|
||||
attr DEVICE comment Channel 1 for DEVICE, see also DEVICE_CH2
|
||||
copy DEVICE DEVICE_CH2
|
||||
attr DEVICE_CH2 stateFormat POWER2
|
||||
attr DEVICE_CH2 comment Channel 2 for DEVICE
|
||||
attr DEVICE_CH2 setList \
|
||||
off:noArg cmnd/MQTTNAME/POWER2 0\
|
||||
on:noArg cmnd/MQTTNAME/POWER2 1\
|
||||
toggle:noArg cmnd/MQTTNAME/POWER2 2
|
||||
|
@ -1,8 +1,7 @@
|
||||
FS20.off light_light_dim_00.svg
|
||||
FS20.on light_light_dim_100.svg
|
||||
off light_light_dim_00.svg
|
||||
on light_light_dim_100.svg
|
||||
|
||||
OFF light_light_dim_00.svg
|
||||
ON light_light_dim_100.svg
|
||||
Aus light_light_dim_00.svg
|
||||
An light_light_dim_100.svg
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user