mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
mqtt2_template: add some zigbee2mqtt helper functions
git-svn-id: https://svn.fhem.de/fhem/trunk@17901 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
66b0dc625a
commit
9cb80f3b16
@ -419,6 +419,29 @@ MQTT2_DEVICE_Undef($$)
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# Utility functions for the AttrTemplates
|
||||
sub
|
||||
zigbee2mqtt_RGB2JSON($)
|
||||
{
|
||||
my $rgb = shift(@_);
|
||||
$rgb =~ m/^(..)(..)(..)/;
|
||||
my( $r, $g, $b ) = (hex($1)/255.0, hex($2)/255.0, hex($3)/255.0);
|
||||
my %color_hash = (r => $r, g => $g, b => $b);
|
||||
my %set_hash = ('transition' => 1, 'color' => \%color_hash);
|
||||
return toJSON(\%set_hash);
|
||||
}
|
||||
|
||||
sub
|
||||
zigbee2mqtt_devStateIcon255($)
|
||||
{
|
||||
my ($name) = @_;
|
||||
return ".*:off:toggle" if(lc(ReadingsVal($name,"state","ON")) eq "off" );
|
||||
my $pct = ReadingsVal($name,"brightness","255");
|
||||
my $s = $pct > 253 ? "on" : sprintf("dim%02d%%",int((1+int($pct/18))*6.25));
|
||||
return ".*:$s:off";
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
@ -48,13 +48,13 @@ filter:TYPE=MQTT2_DEVICE
|
||||
par:NAMEINTHEBRIDGE;name of this device in the bridge;{ AttrVal("DEVICE","readingList","") =~ m,zigbee2mqtt/(.*):, ? $1 : undef }
|
||||
attr DEVICE icon hue_filled_white_and_color_e27_b22
|
||||
attr DEVICE stateFormat {lc ReadingsVal("$name","state",0)}
|
||||
attr DEVICE devStateIcon {devStateIcon255($name)}
|
||||
attr DEVICE devStateIcon {zigbee2mqtt_devStateIcon255($name)}
|
||||
attr DEVICE webCmd toggle:on:off:brightness:color
|
||||
attr DEVICE setList \
|
||||
on:noArg zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"ON"}\
|
||||
off:noArg zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"OFF"}\
|
||||
brightness:colorpicker,BRI,0,15,255 zigbee2mqtt/NAMEINTHEBRIDGE/set {"state":"on","$EVTPART0":"$EVTPART1"}\
|
||||
color:colorpicker,RGB {"zigbee2mqtt/NAMEINTHEBRIDGE/set " . encode_json(convertRGBtoR_G_B($EVTPART1))}
|
||||
color:colorpicker,RGB {"zigbee2mqtt/NAMEINTHEBRIDGE/set " . zigbee2mqtt_RGB2JSON($EVTPART1))}
|
||||
|
||||
name:zigbee2mqtt_smokeDetector
|
||||
filter:TYPE=MQTT2_DEVICE
|
||||
|
Loading…
x
Reference in New Issue
Block a user