I managed to flash RGBW2 with ESPHome and so far it works as expected.
The only problem I have is getting power usage measurements. I have added A0 GPIO pin as ADC and it’s changing value as I increase the power, but it’s not linear.
I took measurements at different percentage and this is how the graph looks like:
It looks like exponential growth, but I can’t seem to get the correct function for proper calculation. Also it would be great to make it more linear as one changes the brightness.
Did anyone solve this?
My config if anyone needs it:
substitutions:
devicename: shelly_rgbw2_generic
friendly_name: Generic firmware for shelly
device_description: Shelly LED dimmer
esphome:
name: ${devicename}
platform: ESP8266
# Set modwifi on shelly devices since they have 2MB of flash
board: modwifi
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Should make wifi signal better (https://www.die-welt.net/2020/04/controlling-roller-shutters-using-a-shelly-25-esphome-and-home-assistant/)
power_save_mode: none
manual_ip:
static_ip: 192.168.50.69
gateway: !secret ip_gateway
subnet: !secret ip_subnet
dns1: !secret ip_dns1
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${friendly_name}
password: !secret ap_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
time:
# Sync RTC time with HA
- platform: homeassistant
id: homeassistant_time
text_sensor:
# Sensor with esphome version and fw build time
- platform: version
name: ${friendly_name} version
# Extra wifi info from device
- platform: wifi_info
ip_address:
name: ${friendly_name} IP
ssid:
name: ${friendly_name} SSID
bssid:
name: ${friendly_name} BSSID
sensor:
# Reports the WiFi signal strength
- platform: wifi_signal
name: ${friendly_name} RSSI
update_interval: 60s
# Reports how long the device has been powered (in hours) since last reboot
- platform: uptime
name: ${friendly_name} uptime
update_interval: 60s
filters:
- lambda: return x / 3600;
unit_of_measurement: "h"
# Analog input (power usage)
- platform: adc
pin: A0
name: "${friendly_name} power"
update_interval: 1s
switch:
- platform: restart
name: ${friendly_name} restart
# Pins for output are found on
# https://translate.google.com/translate?sl=auto&tl=en&u=https%3A%2F%2Fbitekmindenhol.blog.hu%2F2019%2F03%2F30%2Fshelly_rgbw2
binary_sensor:
# HA sensor showing if device is connected
- platform: status
name: ${friendly_name} status
# Switch button
- platform: gpio
pin:
number: GPIO5
#mode: INPUT_PULLUP
#inverted: True
name: ${friendly_name} button
on_click:
then:
- light.toggle:
id: lightid
#internal: true
id: switchid
output:
- id: pwm_r
platform: esp8266_pwm
pin: 12
frequency: 1000 Hz
# min_power: 0.06
- id: pwm_g
platform: esp8266_pwm
pin: 15
frequency: 1000 Hz
# min_power: 0.06
- id: pwm_b
platform: esp8266_pwm
pin: 14
frequency: 1000 Hz
# min_power: 0.06
- id: pwm_w
platform: esp8266_pwm
pin: 4
frequency: 1000 Hz
# min_power: 0.06
light:
- platform: rgbw
name: ${friendly_name} light
default_transition_length: 0.3s
red: pwm_r
green: pwm_g
blue: pwm_b
white: pwm_w
id: lightid
Did you find out how to do it without having to calibrate it? I am using the config below and even though it “works”, it still feels hackish and it’s only thanks to the fact I have a multimeter and get the values. Shelly is able to do it on stock firmware, so do you know what’s the limitation of getting it right from the beginning as well?
Can I ask where you measured the value 1.5834? Is this a current from measuring in series?
The ADC on an ESP8266 is reporting a voltage (not current) from 0-1V (assuming its a bare chip), so 0.39551V and 0.43750V. If one were to open up an RGBW2 to look at where A0 is wired (resistors , etc) one could calculate the current (I think).
In any case, a measurement like yours should be fine and isn’t really a hack at all.
PS Note the ADC is has 1024 levels so 0.0009765625V steps (assuming its linear).