Can anyone help me with this, i’ve tried this in so many variations and it just will not work? Gives me formatting errors.
Thanks
####Wind Direction Start####
- platform: mlx90393
id: mlx
x_axis:
name: "mlx_x"
y_axis:
name: "mlx_y"
z_axis:
name: "mlx_z"
update_interval: 1s
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 5s
lambda: |-
float w0 = id(x);
float w1 = id(y);
w0 = min(max(w0 * 2.0 - 1.0, -1.0), 1.0);
w1 = min(max(w1 * 2.0 - 1.0, -1.0), 1.0);
float w = atan2(w0, w1);
w = 360.0 * w / (2.0 * M_PI) + 180.0;
if ( w >= 360.0 ) w -= 360.0;
if ( w < 0 ) w = 0;
return w;
####END Wind Direction####
zoogara
(Daryl)
September 1, 2023, 9:47am
2
Maybe post the errors it gives you? There is probably a clue in there.
Where are these defined? Not in the yaml you have posted.
Sure, sorry heres the full YAML.
esphome:
name: weather-station
friendly_name: weather-station
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key:
ota:
password:
i2c:
sda: 21
scl: 22
scan: True
sun:
latitude: 36.8509
longitude: 74.7645
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
sensor:
####Wifi Signal Start####
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Signal %"
entity_category: "diagnostic"
####Wifi Signal END###
####Tempreature & Humidity Start####
- platform: sht3xd
temperature:
name: "Temperature"
humidity:
name: "Humidity"
address: 0x44
update_interval: 60s
####Tempreature & Humidity END####
####Rainfall Start####
- platform: pulse_counter
name: 'Rainfall'
id: rain_gauge
# pin ADC1_1
pin:
number: 32
mode: INPUT_PULLUP
internal_filter: 13us
update_interval: 1s
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
# unit_of_measurement: "mm"
icon: "mdi:water"
filters:
- multiply: 1.0000
- platform: integration
name: "Rainfall Per Minute"
id: rain_per_min
time_unit: min
unit_of_measurement: 'mm'
icon: 'mdi:weather-rainy'
sensor: rain_gauge
- platform: total_daily_energy
name: "Total Daily Rain"
power_id: rain_gauge
unit_of_measurement: 'mm'
icon: 'mdi:weather-rainy'
# x60 To convert to aggregated rain amount
filters:
- multiply: 60
accuracy_decimals: 4
####Rainfall End####
- platform: sun
name: "Sun elevation"
type: elevation
update_interval: 120s
- platform: sun
name: "Sun azimuth"
type: azimuth
update_interval: 120s
####Wind Direction END####
####Wind Speed Start####
- platform: pulse_meter
pin:
# Don't forget to add a pulling resistor, see README
number: GPIO33
mode: INPUT
id: wind_speed
unit_of_measurement: 'm/s'
name: "Wind Speed"
icon: 'mdi:weather-windy'
internal_filter: 13us
timeout: 5s
filters:
- multiply: 0.005560619
- sliding_window_moving_average:
window_size: 20
send_every: 20
- platform: copy
name: 'Wind Speed Average'
icon: 'mdi:weather-windy'
id: wind_speed_avg
source_id: wind_speed
unit_of_measurement: 'm/s'
filters:
- throttle_average: 5s
- platform: copy
name: 'Wind Speed (km/h)'
id: wind_speed_kmh
source_id: wind_speed
unit_of_measurement: 'km/h'
icon: 'mdi:weather-windy'
filters:
- multiply: 3.6
- platform: copy
name: 'Wind Speed Average (km/h)'
icon: 'mdi:weather-windy'
id: wind_speed_kmh_avg
source_id: wind_speed_avg
unit_of_measurement: 'km/h'
filters:
- multiply: 3.6
####Wind Speed END####
####FAN Switch Start####
switch:
- platform: gpio
pin: 25
name: "Fan"
inverted: True
####Fan Switch END####
####Status LED Start####
light:
- platform: neopixelbus
type: GRB
variant: WS2811
pin: GPIO23
num_leds: 1
name: "Status LED"
restore_mode: ALWAYS_OFF
####Status LED END####
####Rain Reset Timer Start####
interval:
- interval: 60s
then:
- sensor.integration.reset: rain_per_min
####Rain Reset Timer END####
# Enable time component to reset energy at midnight
time:
- platform: homeassistant
zoogara
(Daryl)
September 1, 2023, 11:29am
4
Apologies - I didn’t drop enough hints. When you’ve been a IT team lead for 30 years you try and make the guys work it out. Try:
####Wind Direction Start####
- platform: mlx90393
id: mlx
x_axis:
name: "mlx_x"
id: "x"
y_axis:
name: "mlx_y"
id: "y"
z_axis:
name: "mlx_z"
update_interval: 1s
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 5s
lambda: |-
float w0 = id(x);
float w1 = id(y);
w0 = min(max(w0 * 2.0 - 1.0, -1.0), 1.0);
w1 = min(max(w1 * 2.0 - 1.0, -1.0), 1.0);
float w = atan2(w0, w1);
w = 360.0 * w / (2.0 * M_PI) + 180.0;
if ( w >= 360.0 ) w -= 360.0;
if ( w < 0 ) w = 0;
return w;
####END Wind Direction####
Note the addition of the id:
in the sensor definition. In the docs:
x_axis (Optional ): The information for the x-axis.
name (Required , string): The name for the x-axis sensor.
id (Optional , ID ): Set the ID of this sensor for use in lambdas.
EDIT: Also apologies for being a smartass. I just announced my retirement at the end of this year so I’m feeling a bit smug.
2 Likes
Its working,
Sorry, what did you change just so i know
Ah wait, spoke too soon haha…
INFO ESPHome 2023.8.2
INFO Reading configuration /config/esphome/weather-station.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing weather-station (board: esp32dev; framework: arduino; platform: platformio/[email protected] )
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
|-- arduino-MLX90393 @ 1.0.0
|-- NeoPixelBus @ 2.7.3
Compiling /data/weather-station/.pioenvs/weather-station/src/main.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib64d/WiFi/WiFiScan.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib64d/WiFi/WiFiServer.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib64d/WiFi/WiFiUdp.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib915/ESPmDNS/ESPmDNS.cpp.o
Archiving /data/weather-station/.pioenvs/weather-station/lib64d/libWiFi.a
Compiling /data/weather-station/.pioenvs/weather-station/libbc6/Update/HttpsOTAUpdate.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/libbc6/Update/Updater.cpp.o
/config/esphome/weather-station.yaml: In lambda function:
/config/esphome/weather-station.yaml:147:18: error: cannot convert 'esphome::sensor::Sensor*' to 'float' in initialization
float w0 = id(x);
^
/config/esphome/weather-station.yaml:148:18: error: cannot convert 'esphome::sensor::Sensor*' to 'float' in initialization
float w1 = id(y);
^
Compiling /data/weather-station/.pioenvs/weather-station/lib398/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib398/libsodium/crypto_core/ed25519/core_ed25519.c.o
*** [/data/weather-station/.pioenvs/weather-station/src/main.cpp.o] Error 1
zoogara
(Daryl)
September 1, 2023, 11:37am
7
Added the Id: lines - so that the ids you were referencing in lambda existed.
zoogara
(Daryl)
September 1, 2023, 11:39am
8
Try float w1 = atof(id(y));
They are probably string arrays and you need to force conversion.
Gives me even more errors
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
|-- arduino-MLX90393 @ 1.0.0
|-- NeoPixelBus @ 2.7.3
Compiling /data/weather-station/.pioenvs/weather-station/src/main.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib398/libsodium/sodium/core.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib398/libsodium/sodium/runtime.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib398/libsodium/sodium/utils.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/openssl/cipher-aesgcm.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/cipher-aesgcm.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/cipher-chachapoly.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/dh-curve25519.c.o
Archiving /data/weather-station/.pioenvs/weather-station/lib398/libsodium.a
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/hash-blake2b.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/hash-blake2s.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/ref/hash-sha256.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/sodium/cipher-aesgcm.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/sodium/cipher-chachapoly.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/sodium/dh-curve25519.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/sodium/hash-blake2b.c.o
/config/esphome/weather-station.yaml: In lambda function:
/config/esphome/weather-station.yaml:147:18: error: cannot convert 'esphome::sensor::Sensor*' to 'float' in initialization
float w0 = id(x);
^
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/backend/sodium/hash-sha256.c.o
/config/esphome/weather-station.yaml:148:18: error: cannot convert 'esphome::sensor::Sensor*' to 'float' in initialization
float w1 = id(y);
^
/config/esphome/weather-station.yaml:151:13: error: redeclaration of 'float w1'
float w1 = atof(id(y));
^~
/config/esphome/weather-station.yaml:148:13: note: 'float w1' previously declared here
float w1 = id(y);
^~
/config/esphome/weather-station.yaml:151:23: error: cannot convert 'esphome::sensor::Sensor*' to 'const char*'
float w1 = atof(id(y));
^
In file included from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cstdlib:75,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdlib.h:36,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/assert.h:21,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/sys/reent.h:503,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/sys/reent.h:17,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/wchar.h:6,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cwchar:44,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/postypes.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/char_traits.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/string:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdexcept:39,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/array:39,
from src/esphome/components/api/api_noise_context.h:3,
from src/esphome/components/api/api_frame_helper.h:13,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/stdlib.h:81:26: note: initializing argument 1 of 'double atof(const char*)'
double atof (const char *__nptr);
~~~~~~~~~~~~^~~~~~
/config/esphome/weather-station.yaml:152:7: error: 'w' was not declared in this scope
w = 360.0 * w / (2.0 * M_PI) + 180.0;
^
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/aes/rijndael-alg-fst.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/blake2/blake2b.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/blake2/blake2s.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/chacha/chacha.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/donna/curve25519-donna-c64.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/donna/curve25519-donna.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/donna/poly1305-donna.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/sha2/sha256.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/sha2/sha512.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/crypto/x25519/x25519.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/protocol/cipherstate.c.o
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/protocol/dhstate.c.o
*** [/data/weather-station/.pioenvs/weather-station/src/main.cpp.o] Error 1
Compiling /data/weather-station/.pioenvs/weather-station/lib2c1/noise-c/protocol/errors.c.o
========================== [FAILED] Took 3.11 seconds ==========================
zoogara
(Daryl)
September 1, 2023, 11:45am
10
Start by not declaring a variable twice:
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 5s
lambda: |-
float w0 = atof(id(x));
float w1 = atof(id(y));
w0 = min(max(w0 * 2.0 - 1.0, -1.0), 1.0);
w1 = min(max(w1 * 2.0 - 1.0, -1.0), 1.0);
float w = atan2(w0, w1);
w = 360.0 * w / (2.0 * M_PI) + 180.0;
if ( w >= 360.0 ) w -= 360.0;
if ( w < 0 ) w = 0;
return w;
####END Wind Direction####
You still may get errors - it’s Friday night and I’m on to the last glass of red from the bottle.
Oh no! Stop drinking I need you! lol
More errors. I really struggle to interpret the errors to actually be able to troubleshoot.
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
|-- arduino-MLX90393 @ 1.0.0
|-- NeoPixelBus @ 2.7.3
Compiling /data/weather-station/.pioenvs/weather-station/src/main.cpp.o
Archiving /data/weather-station/.pioenvs/weather-station/lib2c1/libnoise-c.a
/config/esphome/weather-station.yaml: In lambda function:
/config/esphome/weather-station.yaml:147:23: error: cannot convert 'esphome::sensor::Sensor*' to 'const char*'
float w0 = atof(id(x));
^
In file included from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cstdlib:75,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdlib.h:36,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/assert.h:21,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/sys/reent.h:503,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/sys/reent.h:17,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/wchar.h:6,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cwchar:44,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/postypes.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/char_traits.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/string:40,
Archiving /data/weather-station/.pioenvs/weather-station/lib4fc/libWire.a
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdexcept:39,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/array:39,
from src/esphome/components/api/api_noise_context.h:3,
from src/esphome/components/api/api_frame_helper.h:13,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/stdlib.h:81:26: note: initializing argument 1 of 'double atof(const char*)'
double atof (const char *__nptr);
~~~~~~~~~~~~^~~~~~
/config/esphome/weather-station.yaml:148:23: error: cannot convert 'esphome::sensor::Sensor*' to 'const char*'
float w1 = atof(id(y));
^
In file included from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cstdlib:75,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdlib.h:36,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/assert.h:21,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/sys/reent.h:503,
from /data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/newlib/platform_include/sys/reent.h:17,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/wchar.h:6,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/cwchar:44,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/postypes.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/bits/char_traits.h:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/string:40,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/stdexcept:39,
from /data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0/array:39,
from src/esphome/components/api/api_noise_context.h:3,
from src/esphome/components/api/api_frame_helper.h:13,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/[email protected] +2021r2-patch5/xtensa-esp32-elf/sys-include/stdlib.h:81:26: note: initializing argument 1 of 'double atof(const char*)'
double atof (const char *__nptr);
~~~~~~~~~~~~^~~~~~
Compiling /data/weather-station/.pioenvs/weather-station/lib8c2/arduino-MLX90393/MLX90393.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib8c2/arduino-MLX90393/MLX90393ArduinoHal.cpp.o
Compiling /data/weather-station/.pioenvs/weather-station/lib6b4/SPI/SPI.cpp.o
*** [/data/weather-station/.pioenvs/weather-station/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.28 seconds ==========================
zoogara
(Daryl)
September 1, 2023, 12:00pm
13
Ah - ok - it’s coming back to me now…
Try this - sensors are their own type, so this might work:
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 5s
lambda: |-
float w0 = atof(id(x).state.c_str());
float w1 = atof(id(y).state.c_str());
w0 = min(max(w0 * 2.0 - 1.0, -1.0), 1.0);
w1 = min(max(w1 * 2.0 - 1.0, -1.0), 1.0);
float w = atan2(w0, w1);
w = 360.0 * w / (2.0 * M_PI) + 180.0;
if ( w >= 360.0 ) w -= 360.0;
if ( w < 0 ) w = 0;
return w;
####END Wind Direction####
Getting closer, less errors.
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
|-- arduino-MLX90393 @ 1.0.0
|-- NeoPixelBus @ 2.7.3
Compiling /data/weather-station/.pioenvs/weather-station/src/main.cpp.o
/config/esphome/weather-station.yaml: In lambda function:
/config/esphome/weather-station.yaml:147:32: error: request for member 'c_str' in 'x->esphome::sensor::Sensor::state', which is of non-class type 'float'
float w0 = atof(id(x).state.c_str());
^~~~~
/config/esphome/weather-station.yaml:148:32: error: request for member 'c_str' in 'y->esphome::sensor::Sensor::state', which is of non-class type 'float'
float w1 = atof(id(y).state.c_str());
^~~~~
Archiving /data/weather-station/.pioenvs/weather-station/lib8c2/libarduino-MLX90393.a
Archiving /data/weather-station/.pioenvs/weather-station/lib6b4/libSPI.a
Compiling /data/weather-station/.pioenvs/weather-station/libe02/NeoPixelBus/internal/Esp32_i2s.c.o
*** [/data/weather-station/.pioenvs/weather-station/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.20 seconds ==========================
zoogara
(Daryl)
September 1, 2023, 12:04pm
15
lol! I’m having a sugar fix but not helping the brain. So you were right in the first instance - they are probably already float, but you were referencing the sensor, not the value of the sensor…
Try this:
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 5s
lambda: |-
float w0 = id(x).state;
float w1 = id(y).state;
w0 = min(max(w0 * 2.0 - 1.0, -1.0), 1.0);
w1 = min(max(w1 * 2.0 - 1.0, -1.0), 1.0);
float w = atan2(w0, w1);
w = 360.0 * w / (2.0 * M_PI) + 180.0;
if ( w >= 360.0 ) w -= 360.0;
if ( w < 0 ) w = 0;
return w;
####END Wind Direction####
Thank you so much that worked.
Ill test it for calibration.
I know this is asking a lot, but is there a way to have it report N, SW, S, SW etc.?
zoogara
(Daryl)
September 1, 2023, 12:23pm
18
Ah - so that I have, but unfortunately I do it in HA:
- platform: template
sensors:
named_wind_direction:
friendly_name: 'Wind Ordinal'
value_template: >-
{%if states.sensor.wind_direction.state | float<=11 %}N
{% elif states.sensor.wind_direction.state | float>348 %}N
{% elif states.sensor.wind_direction.state | float<=34 | float>11 %}NNE
{% elif states.sensor.wind_direction.state | float<=56 | float>34 %}NE
{% elif states.sensor.wind_direction.state | float<=79 | float>56 %}ENE
{% elif states.sensor.wind_direction.state | float<=101 | float>79 %}E
{% elif states.sensor.wind_direction.state | float<=124 | float>101 %}ESE
{% elif states.sensor.wind_direction.state | float<=146 | float>124 %}SE
{% elif states.sensor.wind_direction.state | float<=169 | float>146 %}SSE
{% elif states.sensor.wind_direction.state | float<=191 | float>169 %}S
{% elif states.sensor.wind_direction.state | float<=214 | float>191 %}SSW
{% elif states.sensor.wind_direction.state | float<=236 | float>214 %}SW
{% elif states.sensor.wind_direction.state | float<=259 | float>236 %}WSW
{% elif states.sensor.wind_direction.state | float<=281 | float>259 %}W
{% elif states.sensor.wind_direction.state | float<=304 | float>281 %}WNW
{% elif states.sensor.wind_direction.state | float<=326 | float>304 %}NW
{% elif states.sensor.wind_direction.state | float<=348 | float>326 %}NNW
{%- endif %}
So 135 is SE.
You could convert the jinja code to lambda I reckon. If you get stuck then there’s always tomorrow.
I think that could work. Thanks.
Let me do more testing.
Thanks for your help
One quick question regarding the rain gauge, im getting measurements that are about 10ml off.
So im testing my rain gauge using unit_of_measurement: ml and then pouring like 150ml of water in, its reporting 160ml.
Is this a problem, its 10ml out, is this to be expected to not get perfect measurements?
Thanks