ich habe den BH1750 Sensor, der Helligkeiten in Lux ausgibt. Funktioniert einwandfrei mittels I2C Anbindung an meinen ESP01-S. Nun will ich die Hellgkeit logarithmieren und mittels log(x) sollte das funktionieren, bzw hattee mal früher funktioniert.
Der Helligkeitssensor liefert in sensors: den Wert. “bh1750_lux_01”.
WIe lautet die Syntax um daraus den logarithmus zu berechnen ? Der soll dann als “bh1750_loglux_01” ausgegeben werden.
Ich hab folgendes probiert, aber klappt nicht:
- platform: template
name: "bh1750_loglux_01"
id: bh1750_loglux_01
accuracy_decimals: 3
update_interval: 15s
unit_of_measurement: 'lnlux'
state_class: measurement
- lambda: return log(id(bh1750_lux_01).state);
by HarryP: Codezeilen formatiert
Wenn ich raten müsste, versuchs mal mit logf
Sonst bekommst du einen String als Ergebnis.
So hat es geklappt - es wird der ln (natürliche logarithmus) berechnet: (trotzdem danke für die Antwort)
- platform: template
name: "bh1750_loglux_01"
accuracy_decimals: 3
update_interval: 15s
unit_of_measurement: 'lnlux'
state_class: measurement
lambda: return log(id(bh1750_lux_01).state)
ist wohl deshalb kein String weil ich state_class: measurment definiert habe. Oder ?
nächstes Problem. Da Logarithmen von negativen Werten Unsinn sind, muss ich vorher den Sensor auf positive Werte beschränken. Hab folgendes probiert, aber die Synthax macht nicht was ich will. In der Testvariante kommt, egal was ich messe, immer nur der letzte Wert raus… Und nun?
- platform: bh1750
name: "bh1750_lux_01"
id: bh1750_lux_01
address: 0x23
update_interval: 15s
accuracy_decimals: 1
unit_of_measurement: 'lux'
filters:
- lambda: |-
if (id(bh1750_lux_01).state > 0.1 ) {
return (20.0) ;
} else {
return (1.0);
}
#
by HarryP: Zusammenführung Doppelpost
- platform: template
name: "bh1750_luxcut_01"
id: bh1750_luxcut_01
accuracy_decimals: 2
update_interval: 30s
unit_of_measurement: 'lux'
state_class: measurement
lambda: |-
if ( id(bh1750_lux_01).state < 0.1 ) {
return (0.05) ;
} else {
return id(bh1750_lux_01).state ;
}
so funktioniert es einwandfrei…