Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when flashing initial .yaml to Wemos D1 mini #25

Closed
ryknow27 opened this issue May 16, 2024 · 19 comments
Closed

Error when flashing initial .yaml to Wemos D1 mini #25

ryknow27 opened this issue May 16, 2024 · 19 comments

Comments

@ryknow27
Copy link

I am fairly new when it comes to ESPHome. I have been using a bed scale that I flashed using arduino but it hasn't been very reliable and I wanted to try it with ESPHome. I changed the info in the .yaml that I know but, I guess I don't know what else to change. Below is the errors I get. Any help I can get would be greatly appreciated.

`INFO ESPHome 2024.5.0
INFO Reading configuration /config/esphome/bed-scale.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing smartscale (board: d1_mini; framework: arduino; platform: platformio/espressif8266@4.2.1)

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
Compiling .pioenvs/smartscale/src/main.cpp.o
Compiling .pioenvs/smartscale/lib67b/ESP8266WiFi/ESP8266WiFi.cpp.o
Compiling .pioenvs/smartscale/lib67b/ESP8266WiFi/ESP8266WiFiAP.cpp.o
src/main.cpp:37:36: error: 'floatGPIO' was not declared in this scope
37 | globals::RestoringGlobalsComponent auto_tare_difference;
| ^~~~~~~~~
src/main.cpp:37:45: error: template argument 1 is invalid
37 | globals::RestoringGlobalsComponent auto_tare_difference;
| ^
/config/esphome/bed-scale.yaml: In function 'void setup()':
/config/esphome/bed-scale.yaml:146:65: error: 'floatGPIO' was not declared in this scope
146 | name: "Smart Scale HX711 Value"
| ^
/config/esphome/bed-scale.yaml:146:74: error: template argument 1 is invalid
146 | name: "Smart Scale HX711 Value"
| ^
/config/esphome/bed-scale.yaml:147:25: error: request for member 'set_component_source' in '
auto_tare_difference', which is of non-class type 'int'
147 | internal: False
| ^
/config/esphome/bed-scale.yaml:149:25: error: request for member 'set_name_hash' in '
auto_tare_difference', which is of non-class type 'int'
149 | # apply auto_tare difference
| ^~~~~~~~~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:61:29: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
61 | id(auto_tare_difference) = id(initial_zero) - id(smart_scale_hx711_value_raw).state;
| ^~~~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:91:36: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
91 | return id(auto_tare_difference);
| ^~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:132:98: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
132 | - lambda: 'return id(smart_scale_hx711_value_raw).state < (id(initial_zero) - id(auto_tare_difference));'
| ^~~~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:136:29: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
136 | id(auto_tare_difference) += 10;
| ^~~~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:140:29: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
140 | id(auto_tare_difference) -= 10;
| ^~~~~
/config/esphome/bed-scale.yaml: In lambda function:
/config/esphome/bed-scale.yaml:150:40: error: request for member 'value' in '* auto_tare_difference', which is of non-class type 'int'
150 | - lambda: 'return x + id(auto_tare_difference);'
| ^~~~~
In file included from src/esphome/components/api/api_connection.h:7,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/application.h: In instantiation of 'C* esphome::Application::register_component(C*) [with C = int]':
/config/esphome/bed-scale.yaml:148:46: required from here
src/esphome/core/application.h:183:50: error: static assertion failed: Only Component subclasses can be registered
183 | static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
| ^~~~~
Compiling .pioenvs/smartscale/lib67b/ESP8266WiFi/ESP8266WiFiGeneric.cpp.o
*** [.pioenvs/smartscale/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.62 seconds ==========================
`

@markusressel
Copy link
Owner

Could be that you are compiling for the wrong board type.
Did you change the platform configuration to match your board?
Can you post your config?

@ryknow27
Copy link
Author

ryknow27 commented May 16, 2024

I actually just found the issue, I had some extra text in the code somehow, see below:

  • id: auto_tare_difference
    type: floatGPIO
    restore_value: yes
    initial_value: '0'
    Not sure how GPIO got in there next to float but after removing it, it of course works fine.
    Thanks for responding.

@ryknow27
Copy link
Author

ryknow27 commented May 16, 2024

Ok, well I was able to successfully flash it but it now stays offline. I've tried changing the WiFi info but no luck. Below is the config:


esphome:
  name: bed
  platform: ESP8266
  board: d1_mini

globals:
  - id: initial_zero
    type: float
    restore_value: yes
    # NOTE: make sure to align this value to the one used in "calibrate_linear" below!
    initial_value: '-481989'
    
  - id: auto_tare_enabled
    type: bool
    restore_value: yes
    initial_value: 'true'

  - id: auto_tare_difference
    type: float
    restore_value: yes
    initial_value: '0'

wifi:
  fast_connect: False  # needed for hidden SSID
  networks:
    - ssid: -mywifi-
      bssid: 'xx:xx:xx:00:d0:71'
      password: xxxx
      hidden: false
  #manual_ip:
  #  static_ip: 192.168.5.49
  #  gateway: 192.168.5.1
  #  subnet: 255.255.255.0

api:
  password: "qgPSetaocBbDSIaTjgKOY8d7os/iG7Z58r86rL/JWcI="

# Enable logging
logger:
  level: ERROR

ota:
  password: "2168c2d5c2d16e65d12c415f69963752"

status_led:
  pin:
    number: GPIO14
    inverted: True

button:

  ## Button used to initiate a manual tare
  - platform: template
    id: smart_scale_manual_tare_action_switch
    name: "Smart Scale Manual Tare Action"
    icon: mdi:scale-balance
    on_press:
      - lambda: |-
          id(auto_tare_difference) = id(initial_zero) - id(smart_scale_hx711_value_raw).state;

switch:
  ## Switch to enable/disable the auto tare feature
  - platform: template
    id: smart_scale_continuous_tare_enabled
    name: "Smart Scale Continuous Tare Enabled"
    lambda: |-
      return id(auto_tare_enabled);
    turn_on_action:
      - lambda: |-
          id(auto_tare_enabled) = true;
    turn_off_action:
      - lambda: |-
          id(auto_tare_enabled) = false;

## Sensor Configuration ##
sensor:
  # template sensors from global variables
  - platform: template
    id: smart_scale_initial_zero
    name: "Smart Scale Initial Zero"
    lambda: |-
      return id(initial_zero);
    update_interval: 1s
    
  - platform: template
    id: smart_scale_auto_tare_difference
    name: "Smart Scale Auto Tare Difference"
    lambda: |-
      return id(auto_tare_difference);
    update_interval: 1s
    
  # sensors imported from home assistant
  - platform: homeassistant
    id: homeassistant_initial_zero
    entity_id: input_number.smart_scale_initial_zero
    on_value:
      then:
        - lambda: |-
            id(initial_zero) = x;
  
  # RAW Scale input
  - platform: hx711
    id: smart_scale_hx711_value_raw
    internal: True
    dout_pin: GPIO2
    clk_pin: GPIO3
    gain: 128
    update_interval: 0.2s
    filters:
      - quantile:
          window_size: 10
          send_every: 1
          send_first_at: 1
          quantile: .9
    on_value:
      then:
        - sensor.template.publish:
            id: smart_scale_hx711_value
            state: !lambda 'return id(smart_scale_hx711_value_raw).state;'
        - if:
            condition:
              and:
                - lambda: 'return id(auto_tare_enabled);'
                # current smart scale value is below approx. 10KG (raw value -275743) aka nobody is standing on the scale
                - lambda: 'return id(smart_scale_hx711_value).state < 10.0;'
            then:
              - if:
                  condition:
                    # current raw scale value is below expected zero value
                    - lambda: 'return id(smart_scale_hx711_value_raw).state < (id(initial_zero) - id(auto_tare_difference));'
                  then:
                    # INcrease Auto-Tare offset to slowly align real zero value with expected zero value
                    - lambda: |-
                        id(auto_tare_difference) += 10;
                  else:
                    # DEcrease Auto-Tare offset to slowly align real zero value with expected zero value
                    - lambda: |-
                        id(auto_tare_difference) -= 10;

    
  # Mapped value to KG
  - platform: template
    id: smart_scale_hx711_value
    name: "Smart Scale HX711 Value"
    internal: False
    filters:
      # apply auto_tare difference
      - lambda: 'return x + id(auto_tare_difference);'
      # apply rough calibration
      - calibrate_linear:
          # retrieve these values by evaluating the raw values with loads of known mass.
          # note that a bigger difference between measurements usually results in higher resolution,
          # so measure 0 Kg and the highest known mass you have (like f.ex. your own weight, measured by a normal scale with good accuracy)
          - -481989 -> 0
          - 1339163 -> 88.3
      # map values below 0.1 to 0 (to decrease value changes due to random fluctuation)
      - lambda: |-
          if (x <= 0.1) {
            return 0.0;
          } else {
            return x;
          }
          
    unit_of_measurement: kg
    accuracy_decimals: 2
    # the sensor will automatically update through the 'sensor.template.publish' call
    update_interval: never```

@ryknow27
Copy link
Author

ryknow27 commented May 16, 2024

I'm not sure if the other format and info such as "bssid" and whatever else is needed or not but I changed it to the following format and it goes online now.

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

@ryknow27
Copy link
Author

Sorry, one more thing, I tried exposing the raw sensor to home assistant by changing True to False but I am not seeing the sensor anywhere in home assistant. Do you know where I should see it?

@markusressel
Copy link
Owner

It should be listed in:
Settings -> Devices & Services -> Entities (Tab) -> Search for "smart scale"

@ryknow27
Copy link
Author

ryknow27 commented May 17, 2024

It should be listed in: Settings -> Devices & Services -> Entities (Tab) -> Search for "smart scale"

Thank you again for replying, but that's where I was looking, it's just not there. I've changed it to "False", saved and flashed it and tried restarting HA but it still doesn't show up. I of course could be doing something else wrong :)

I've also noticed when trying to read the ESPHome logs, I'm not getting anything except for what you can see in the attached image.

1
2
3

@markusressel
Copy link
Owner

Hmm, indeed I also cannot see it. Seems like something changed on the ESPHome side since this definitely worked at some point.

I have updated the configuration to include a diagnostic sensor that will show the initial raw sensor value of the HX711 chip. This value will only update a single time when the ESP boots up. If you want to get a new value while the ESP is still on you can trigger an update using the "manual tare" button action. Otherwise simply reboot the ESP to get a new value.

See #27

Let me know if that helps.

@ryknow27
Copy link
Author

ryknow27 commented May 17, 2024

Okay so, I wasn't able to get the smart_scale_hx711_value_raw sensor to show up, so I just created another one (shown below) and had it return the raw value. After that, the new sensor showed up and I was able to get everything working correctly now. Hopefully it was the correct return value I was looking for, it does seem to work good now so I am assuming it was. Thanks again for your help.

- platform: template
    id: smart_scale_value_raw2
    name: "Smart Scale Value Raw2"
    lambda: |-
      return (int((id(smart_scale_hx711_value_raw).state)));
    update_interval: 0.2s

@ryknow27
Copy link
Author

Hmm, indeed I also cannot see it. Seems like something changed on the ESPHome side since this definitely worked at some point.

I have updated the configuration to include a diagnostic sensor that will show the initial raw sensor value of the HX711 chip. This value will only update a single time when the ESP boots up. If you want to get a new value while the ESP is still on you can trigger an update using the "manual tare" button action. Otherwise simply reboot the ESP to get a new value.

See #27

Let me know if that helps.

Lol, I didn't see your reply until after sending my last one. Thank you for looking into it and I will add the new sensor you created and if I have any issues, I will try what you said.
Thanks!

@markusressel
Copy link
Owner

@ryknow27 No worries 😄

I would recommend to use the solution I created in #27 or at least to remove the sensor you created after you have finished the calibration, since updating this sensor every 0.2 seconds will cause a lot of network traffic that is not necessary and might even cause problems for other devices on the network.

Good to hear you found a solution and that it works well 🤓

@ryknow27
Copy link
Author

@markusressel Sorry to bother you again but do you know if the lovelace card still works? I've tried installing it a few time but I keep getting "Custom element doesn't exist: multiple-entity-row." I have installed per the instructions for the card but haven't had any luck. I was about to bring up an issue on that github but thought I would ask here first.

@markusressel
Copy link
Owner

I am still using it, so I would assume it does. I have it installed years ago though.

@ryknow27
Copy link
Author

Okay, I was able to get it to install but I am now getting the following:
1
I left out the entity: input.number.weight_markus info as I'm not sure how you created that entity. Is that the reason it wouldn't work?

@ryknow27
Copy link
Author

Should have asked earlier as well but would you mind sharing how/where you created the entity for Markus's weight?

@markusressel
Copy link
Owner

markusressel commented May 19, 2024

"input_number.weight_markus" is a custom "input number" entity defined through the home assistant configuration yaml.

See: https://www.home-assistant.io/integrations/input_number/

The value of this input number is updated through an automation that looks for the scale value to be above a certain threshold for a certain amount of time (3 seconds or something like that).

With this setup I can step on the scale at any time, wait a couple of seconds and my current weight will be saved in the history of this entity.

Home Assistant
Instructions on how to integrate the input number integration into Home Assistant.

@markusressel
Copy link
Owner

Regarding the error: multiple entity row requires both a main entity definition as well as a list of entities to show next to it. You seem to be missing thr main entity (the one shown on the right end, which will also dictate the behavior of the card).

@ryknow27
Copy link
Author

Regarding the error: multiple entity row requires both a main entity definition as well as a list of entities to show next to it. You seem to be missing thr main entity (the one shown on the right end, which will also dictate the behavior of the card).

Thank you, I'll look into that!

@markusressel
Copy link
Owner

I am closing this, since the original issue is fixed. Feel free to open another issue if anything comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants