Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 105737

ESPhome custom component for us-100 uart can't compile after update

$
0
0

Hello,

I use esphome to monitor my oil tanks. In every tank i have an esp8266 that talks to an us-100 ultrasonic sensor via uart (uart mode is hardwired and the sensors themself are glued into an housing, so it’s not easy to change communication mode to trigger/echo pins like the ultrasonic example shows).

This is my code, that works with esphome 2024:

esphome:
  name: esp8266-us100-tank3
  friendly_name: esp8266-us100-tank3
  includes:
    - us100.h

esp8266:
  board: esp01_1m

# Enable logging
logger:
  # disable serial ogging, we need it fpr us100
  baud_rate: 0


# Enable Home Assistant API
api:
  encryption:
    key: "mysuperstrongencryptionkeyplaceholder"

ota:
  - platform: esphome
    password: "mysuperstrongencryptionkeyplaceholder"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp8266-Us100-Tank3"
    password: "mysuperstrongencryptionkeyplaceholder"

captive_portal:

uart:
  id: uart_bus
  tx_pin: GPIO0
  rx_pin: GPIO2
  baud_rate: 9600

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
  - platform: custom
    lambda: |-
      auto us100 = new US100(id(uart_bus));
      App.register_component(us100);
      return {
        us100->distsensor,
        us100->tempsensor,
      };
    sensors:
      - name: "US100 Distance"
        id: "tank3_distance"
        unit_of_measurement: mm
        icon: "mdi:tape-measure"
      - name: "US100 Temperature"
        id: "tank3_temperature"
        unit_of_measurement: °C
  - platform: template
    name: "Ölmenge in Liter"
    accuracy_decimals: 0
    unit_of_measurement: "L"
    lambda: |-
      int liters = 0;
      if ( ( id(tank3_distance).state > 1500 ) || ( id(tank3_distance).state < 10 ) ) {
        liters = 0;
      } else {
        liters = ( 1500 - (int) id(tank3_distance).state ) * 0.6933 ;
      }
      if (liters > 1050)
      {
        return 0;
      }
      else if (liters > 0)
      {
        return liters;
      }
      else
      {
        return 0;
      }
    update_interval: 60s
    filters:
      - sliding_window_moving_average:
          window_size: 60
          send_every: 60
          send_first_at: 60
  - platform: template
    name: "Ölmenge in Prozent"
    accuracy_decimals: 0
    unit_of_measurement: "%"
    lambda: |-
      int percent = 0;
      if ( ( id(tank3_distance).state > 1500 )  || ( id(tank3_distance).state < 10 ) ) {
        return 0;
      } else {
        // = Füllhöhe[mm]                         * ( 100% / maxFüllhöhe(1500mm) ) = Füllhöhe[mm] * 0,06666666666667
        // = ( maxFüllhöhe(1500mm) - t3dist[mm] ) * 0,0666666666667
        //return ( ( 1500 - (int) id(tank3_distance).state ) * 0.067 );
        percent = ( 1500 - (int) id(tank3_distance).state ) * 0.067;
      }
      if (percent > 100)
      {
        return 0;
      }
      else if (percent > 0)
      {
        return percent;
      }
      else
      {
        return 0;
      }
    update_interval: 60s
    filters:
      - sliding_window_moving_average:
          window_size: 60
          send_every: 60
          send_first_at: 60

My actual solution is to stay at esphome 2024.12. Does anybody know how the code has to be modified to compile with esphome2025.03 ?

Best regards
Marcel

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 105737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>