Hallo
nach langem suchen und unendlich vielen Versuchen frage ich gerne hier nach einer Hilfestellung.
Inde Bastelkiste habe ich einen alten Shelly RGBW2 gefunden und mit ESPHome geflasht. Alles funktioniert aus dem MQTT Explorer. Ich kann die Farbe und den Status etc. steuern, genau so wie ich es gebrauchen könnte. Der Shelly benötigt die folgende MQTT Json Message Struktur:
{
"effect": "Random",
"color_mode": "rgb",
"state": "ON",
"brightness": 255,
"color": {
"r": 200,
"g": 0,
"b": 155
}
}
So jetzt zu meiner Frage.... wie kann ich aus meinem MQTT2_Device diese Message generieren.
Am schönsten wäre es mit setlist die Json Message zu bauen.
PS: Das Lesen den Statuses funktioniert mit readinglist perfekt.
Hmmm, schau dir mal das attrTemplate "shellybulb" an, das geht zumindest in diese Richtung. Da gibt es z.B. folgende Zeile:
rgb:colorpicker,RGB {return 'shellies/DEVNAME/color/0/command off' if $EVTPART1 eq '000000'; return 'shellies/DEVNAME/color/0/set {"turn":"on","mode":"white","temp":4000}' if $EVTPART1 eq 'FFFFFF'; $EVTPART1=~/(..)(..)(..)/; return if !defined $3; if($1 ne $2 || $2 ne $3){q(shellies/DEVNAME/color/0/set {"mode":"color","gain":"100","turn":"on","red":).hex($1).q(,"green":).hex($2).q(,"blue":).hex($3).'}'}else{q(shellies/DEVNAME/color/0/set {"turn":"on","mode":"white","brightness":).int(hex($1)/2.55).'}'}}
Vermutlich gibt es noch mehr, wenn man nach "qq"-Anweisungen in den setList-Vorschlägen in der attrTemlate-file schaut (https://svn.fhem.de/trac/browser/trunk/fhem/FHEM/lib/AttrTemplate/mqtt2.template).
besten Dank, das war der richtige Ansatz. Meine Setlist sieht nun so aus:
rgb:colorpicker,RGB {return 'Home/Shelly_RGBW_Küche/light/ledstrip_shelly_rgbw2/command {"turn":"on","mode":"white","temp":4000}' if $EVTPART1 eq 'FFFFFF'; $EVTPART1=~/(..)(..)(..)/; return if !defined $3; if($1 ne $2 || $2 ne $3){q(Home/Shelly_RGBW_Küche/light/ledstrip_shelly_rgbw2/command {"effect":"None","color_mode":"rgb","state":"ON","brightness":255,"color":{"r": ).hex($1).q(,"g": ).hex($2).q(,"b": ).hex($3).'}}'}}
on {return 'Home/Shelly_RGBW_Küche/light/ledstrip_shelly_rgbw2/command {"effect":"None","color_mode":"rgb","state":"ON","brightness":255,"color":{"r":100,"g":100,"b":100}}'}
off {return 'Home/Shelly_RGBW_Küche/light/ledstrip_shelly_rgbw2/command {"effect":"None","color_mode":"rgb","state":"OFF","brightness":255,"color":{"r":100,"g":100,"b":100}}'}
Die ESPHome Yaml ist extrem einfach:
substitutions:
device_name: Shelly_RGBW
esphome:
name: shelly-rgbw2
friendly_name: Shelly_RGBW2
esp8266:
board: esp01_1m
# Enable logging
logger:
# # Enable Home Assistant API
# api:
# encryption:
# key: "rc+aFqHCYKiJA8lqpqMzMeL7fdtmJCaM41YalhF5ozI="
ota:
- platform: esphome
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Shelly-Rgbw2 Fallback Hotspot"
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
mqtt:
broker: !secret mqtt_broker
username: !secret mqtt_username
password: !secret mqtt_password
topic_prefix: Home/Shelly_RGBW_Küche
# Example configuration entry
web_server:
port: 80
captive_portal:
light:
- platform: rgb # platform: rgbw
name: ledstrip_shelly_rgbw2
id: light1
red: pwm_r
green: pwm_g
blue: pwm_b
# white: pwm_w
effects:
- random:
- strobe:
- flicker:
output:
- platform: esp8266_pwm
pin: GPIO12
frequency: 1000 Hz
id: pwm_r
max_power: 80%
- platform: esp8266_pwm
pin: GPIO15
frequency: 1000 Hz
id: pwm_g
max_power: 80%
- platform: esp8266_pwm
pin: GPIO14
frequency: 1000 Hz
id: pwm_b
max_power: 80%
- platform: esp8266_pwm
pin: GPIO4
frequency: 1000 Hz
id: pwm_w
max_power: 80%