Ok, after a while, I’ve updated my ESPHome and my old code stopped working. Any tips?
This is my current configuration (was using ‘text_sensor’, changed to new code in this thread, still not working)
esphome:
name: medidor_energia_adsb
platform: ESP8266
board: esp01_1m
wifi:
ssid: "Skynet"
password: !secret wifi_skynet_pwd
manual_ip:
static_ip: 192.168.22.42
gateway: 192.168.22.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Medidor Energia Adsb"
password: "JunhgKtFu2z7"
captive_portal:
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
web_server:
port: 80
auth:
username: jmaurin
password: !secret web_server_pwd
uart:
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 9600
#parity: EVEN
external_components:
- source: github://dentra/esphome@tuya-raw-fix
components: ["tuya"]
- source: github://dentra/esphome-components
# Example configuration entry
time:
- platform: homeassistant
id: homeassistant_time
# Register the Tuya MCU connection
tuya:
on_datapoint_update:
- sensor_datapoint: 6
datapoint_type: raw
then:
- lambda: |-
id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
id(power).publish_state((x[6] << 8 | x[7]) * 0.1);
#text_sensor:
# - platform: tuya
# id: tuya_raw_test
# sensor_datapoint: 6
# on_value:
# lambda: |
# auto d = tuya::rawdecode(x);
# id(voltage).publish_state((d[0] << 8 | d[1]) * 0.1);
# id(current).publish_state((d[3] << 8 | d[4]) * 0.001);
# id(power).publish_state((d[6] << 8 | d[7]));
sensor:
- platform: "tuya"
id: total
name: "Energy Total"
sensor_datapoint: 1
accuracy_decimals: 3
filters:
- multiply: 0.001
unit_of_measurement: "kWh"
icon: "mdi:sigma"
device_class: "energy"
- platform: template
id: voltage
name: "Voltage"
unit_of_measurement: "V"
icon: "mdi:sine-wave"
device_class: "voltage"
- platform: template
id: current
name: "Current"
unit_of_measurement: "A"
icon: "mdi:current-ac"
device_class: "current"
- platform: template
id: power
name: "Active Power"
unit_of_measurement: "W"
accuracy_decimals: 0
icon: "mdi:flash"
device_class: "power"
- platform: "energy_monitoring"
power: power
voltage: voltage
current: current
apparent_power:
name: "Apparent Power"
reactive_power:
name: "Reactive Power"
power_factor:
name: "Power Factor"
switch:
- platform: "tuya"
name: "Power"
switch_datapoint: 16
icon: "mdi:power"
And this is the error while validating or compiling:
INFO Reading configuration /config/esphome/medidor_energia_adsb.yaml...
INFO Updating https://github.com/dentra/esphome.git@tuya-raw-fix
INFO Updating https://github.com/dentra/esphome-components.git@None
ERROR Unable to import component tuya:
Traceback (most recent call last):
File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
ERROR Unable to import component tuya.sensor:
Traceback (most recent call last):
File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
ERROR Unable to import component tuya.switch:
Traceback (most recent call last):
File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
WARNING 'medidor_energia_adsb': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Detected timezone 'TZ' with UTC offset -3
Failed config
tuya: [source /config/esphome/medidor_energia_adsb.yaml:57]
Component not found: tuya.
on_datapoint_update:
- sensor_datapoint: 6
datapoint_type: raw
then:
- lambda: |-
id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
id(power).publish_state((x[6] << 8 | x[7]) * 0.1);
sensor.tuya: [source /config/esphome/medidor_energia_adsb.yaml:81]
Platform not found: 'sensor.tuya'.
platform: tuya
id: total
name: Energy Total
sensor_datapoint: 1
accuracy_decimals: 3
filters:
- multiply: 0.001
unit_of_measurement: kWh
icon: mdi:sigma
device_class: energy
switch.tuya: [source /config/esphome/medidor_energia_adsb.yaml:122]
Platform not found: 'switch.tuya'.
platform: tuya
name: Power
switch_datapoint: 16
icon: mdi:power