rudiB
December 3, 2022, 3:15pm
21
This is how i solved this part. You don’t need the lambda part… Now also working without load. (sorry don’t know how to publich the data in the way You people do
switch:
- platform: template
name: $friendly_name
optimistic: true
id: relay_1
# lambda: |-
# if (isnan(id(w_sensor).state)) {
# return {};
# } else if (id(w_sensor).state > 4) {
# // Running
# return true;
# } else {
# // Not running
# return false;
# }
turn_off_action:
- switch.turn_on: relay_off
turn_on_action:
- switch.turn_on: relay_on
- platform: gpio
restore_mode: ALWAYS_OFF
internal: true
id: relay_off
pin: GPIO04
on_turn_on:
- switch.turn_on: relay_off
- delay: 500ms
- switch.turn_off: relay_off # bi-stable relay so no need to keep on.
- light.turn_off: switch_led
interlock: [relay_on]
- platform: gpio
restore_mode: ALWAYS_OFF
internal: true
id: relay_on
pin: GPIO02
on_turn_on:
- switch.turn_on: relay_on
- delay: 500ms
- switch.turn_off: relay_on # bi-stable relay so no need to keep on.
- light.turn_on: switch_led
interlock: [relay_off]
- platform: restart
name: $friendly_name Restart
1 Like
AdamosHA
(Adamos Ha)
December 5, 2022, 2:00pm
22
rudiB:
lambda…
Hello
I confirm with these #lambda settings…
The switch works.
But after reboot or power outage it doesn’t show status in HA.
edit
is it possible to go back to the original sonoff firmware ?
GenGT
January 10, 2023, 2:25pm
23
Hi, you can go back to the original sonoff firmware via serial, but only if you have a backup from the original firmware. I have no problem with the status… Try with tasmota firmware, if you select he correct model all will run out of the box
1 Like
Hello there,
I tried every trick in the book and then some.
My recently bought sonoff powr320D works fine with tasmota but not is esphome.
I tried even the basic CSE7766 Power Sensor examples. Esphome 2023.5.5 CSE7766 platform doen’t respond at all. It gives no readings. Not even in logs. I checked the chip on the PCB and it is the CSE7759B-SO.
Maybe CSE7766 platform it is not working properly with this chip?
Does anybody have any suggestions?
Hello, after debug uart on powr316 & reading CSE7766 datasheet, i add the line “parity: even” on uart config . Now i can view every electrical data. perhaps it can help you ?
2 Likes
Qtip
June 14, 2023, 8:50am
26
chris1313:
parity: even
Perfect. That does the trick!!!.. Thanks Chris
uart:
rx_pin: GPIO16
baud_rate: 4800
parity: even
1 Like
Thank you. I will try that. In the meantime I have tried a different approach.
It also seems to work commenting out the “baud_rate” line in logger.
logger:
level: DEBUG
# baud_rate: 0
uart:
- rx_pin: GPIO16
baud_rate: 4800
sensor:
- platform: cse7766
Qtip
June 15, 2023, 7:42am
28
Agree.
Even commenting out the the ’ level: DEBUG ’ line works.
logger:
# level: DEBUG
# baud_rate: 0
uart:
rx_pin: GPIO16
baud_rate: 4800
# parity: even
beaj
(Brian Johnstone)
September 2, 2023, 7:21pm
29
I came across this thread after dealing with an issue of not being able to turn off the relay on my Sonoff 320D.
After looking at the code copied from Sonoff-POW-Elite-20a I came to the same conlusion that the Lamda code was the problem.
# if (isnan(id(w_sensor).state)) {
# return {};
# } else if (id(w_sensor).state > 4) {
# // Running
# return true;
# } else {
# // Not running
# return false;
# }
I don’t know the rational behind the code but there is a serious problem with it.
If there is no current flowing you cannot turn off the relay. In my use case I am using this to switch on an immersion heater. If the immersion heather thermostat cuts power to the heater you cannot turn off the relay supplying power to the immersion heater.
I have updated the ESP code to comment out the Lamda code as other have done and now have proper control over the relay state.
Spirch
(Spirch)
September 21, 2023, 2:33am
30
what is the current recommended configuration for the sonoff powr320d ?
can you paste the whole yaml?
Chojino
October 27, 2023, 3:01pm
31
Hello guys, it’s been a year since I posted my config file, and I had to revisit it cuz I updated the EspHome version of the device and I lost all readings and I thought I could use my original post as a backup config, but was even better, chris1313 on post 25 solved it.
Apparently now you can find the config file on esphome website but google seems to like this post so here goes my updated config file with chris1313 solution and beaj improvement:
substitutions:
device_name: your_device_name
device_ip: your_device_ip
esphome:
name: ${device_name}
esp32:
board: nodemcu-32s
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: ${device_ip}
gateway: !secret wifi_gateway
subnet: 255.255.255.0
ap:
password: !secret wifi_password
captive_portal:
logger:
baud_rate: 0
api:
reboot_timeout: 60min
encryption:
key: !secret api_key_cryp
ota:
password: !secret ota_password
web_server:
port: 80
uart:
rx_pin: GPIO16
baud_rate: 4800
parity: even
time:
- platform: homeassistant
id: homeassistant_time
sensor:
- platform: cse7766
update_interval: 2s
current:
name: ${device_name} Current
id: a_sensor
voltage:
name: ${device_name} Voltage
id: v_sensor
power:
name: ${device_name} Power
id: w_sensor
energy:
name: ${device_name} Energy
id: wh_sensor
- platform: total_daily_energy
name: ${device_name} Total Daily Energy
power_id: w_sensor
- platform: wifi_signal
name: ${device_name} Wifi Signal Strength
update_interval: 60s
- platform: uptime
id: uptime_sensor
internal: True
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
- platform: template
name: ${device_name} Power Factor
device_class: power_factor
id: power_factor
lambda: return id(w_sensor).state / id(v_sensor).state / id(a_sensor).state;
binary_sensor:
- platform: gpio
pin: GPIO00
id: reset
internal: true
filters:
- invert:
- delayed_off: 10ms
on_click:
- max_length: 350ms # short press to toggle the relay
then:
switch.toggle: relay_1
- min_length: 360ms # long press to cycle display info
max_length: 3s
then:
- if:
condition:
binary_sensor.is_on: page
then:
binary_sensor.template.publish:
id: page
state: OFF
else:
binary_sensor.template.publish:
id: page
state: ON
- platform: template # this is a fake sensor to tell the screen which info to show on display
id: page
publish_initial_state: true
internal: true
- platform: template
name: ${device_name} subordinate device
id: subordinate_device_on
lambda: |-
if (isnan(id(w_sensor).state)) {
return {};
} else if (id(w_sensor).state > 4) {
// Running
return true;
} else {
// Not running
return false;
}
display:
platform: tm1621
id: tm1621_display
update_interval: 1s
cs_pin: GPIO25
data_pin: GPIO14
read_pin: GPIO26
write_pin: GPIO27
lambda: |-
if (id(page).state) {
it.display_voltage(true);
it.display_kwh(false);
it.printf(0, "%.1f", id(v_sensor).state);
it.printf(1, "%.1f", id(a_sensor).state);
} else {
it.display_voltage(false);
it.display_kwh(true);
it.printf(0, "%.1f", id(wh_sensor).state);
it.printf(1, "%.1f", id(w_sensor).state);
}
output:
- platform: ledc
id: led
pin:
number: GPIO18
inverted: True
switch:
- platform: gpio
name: ${device_name}_switch
icon: "mdi:light-switch-off"
pin: GPIO13
id: relay_1
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_on: switch_led
on_turn_off:
- light.turn_off: switch_led
- platform: restart
name: ${device_name} Restart
text_sensor:
- platform: template
name: ${device_name} Uptime
id: uptime_human
icon: mdi:clock-start
- platform: wifi_info
ip_address:
name: ${device_name} IP
ssid:
name: ${device_name} SSID
bssid:
name: ${device_name} BSSID
light:
- platform: monochromatic
id: switch_led
output: led
internal: True
- platform: status_led
id: wifi_status_led
internal: True
pin:
number: GPIO05
inverted: True
interval:
- interval: 30s
then:
if:
condition:
wifi.connected:
then:
- light.turn_on: wifi_status_led
else:
- light.turn_off: wifi_status_led