I have some Athom smart plugs v2, and even though I know people have been reporting issues with those devices, they work fine for me in general.
I use one for my projector, to detect when it’s powered on/off and then start appropriate actions such as turning on my Yamaha receiver and opening the projector screen. This works fine in general, but the default sensor update frequency is quite long for this purpose (10 seconds), so I decided to change that.
I added this to substitions:
sensor_update_interval: "1s"
The main configuration is here and I’m using the defaults other than the above and the device names:
github://athom-tech/athom-configs/athom-smart-plug-v2.yaml
As you can see in there, this substitution is applied to the power monitoring sensors. And it works in general.
Now, the problem:
while the update frequency of the power/energy sensors is now usually 1 per second, when the projector turns off, it is noticeably longer. See the power graph here:
It was updating every second all the time (including when it started earlier), but when the projector was turned off, there is no update for 11 seconds. Sometimes this is a little shorter I think, but always at least several seconds.
Is this just the beauty of the device, that for whatever reason it struggles to keep up when power suddenly goes down, or something wrong with my config, anything I could do to speed up the detection of the projector powering down?
Sure? Not the normal/default behavior of not resending same values?
When turned off I expect 0W, and after 1 second still 0W and after 2 seconds still 0W… So the HA sensor tells you essentially how long it is 0W already.
Otherwise the esphome docs mentioned force_update which will clutter your database but might is what you want for some reason?
I don’t think this is it, because it is only sending the first 0 W value 11 seconds after the last ~220 W value. I’m ok with it not resending the 0 W after it sent it once. (reposting as I clicked the wrong reply button)
I don’t have anything in the logs. I didn’t think about this before, but I will try changing the logs level, as the level from Athom github is INFO. I’ll try changing to DEBUG.
I find debug logs really useful for bug hunting … sometimes not necessarily bug hunting but real world view of what is going on under the hood. Not always obvious until you can see what is being spat out.
Alright, there’s something in the debug logs indeed when this happens.
(note the initial power is different here than in my previous screenshots, as I connected the plug to a phone charger now for a quicker test, but same behaviour happened).
[13:34:22.268][D][sensor:129]: 'Power' >> 46.5 W
[13:34:22.268][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:22.268][D][sensor:129]: 'Current' >> 0.32 A
[13:34:22.268][D][sensor:129]: 'Voltage' >> 246.8 V
[13:34:22.268][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:22.268][D][sensor:129]: 'Power Factor' >> 0.59
[13:34:22.269][D][sensor:129]: 'Apparent Power' >> 79.1 VA
[13:34:22.743][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:22.744][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:23.265][D][cse7766:181]: Impossible reactive power: -28.6433 is negative
[13:34:23.266][D][cse7766:192]: Impossible power factor: 2.6044 not in interval [0, 1]
[13:34:23.266][D][sensor:129]: 'Reactive Power' >> 29.0 var
[13:34:23.269][D][sensor:129]: 'Voltage' >> 246.8 V
[13:34:23.269][D][sensor:129]: 'Power Factor' >> 0.59
[13:34:23.269][D][sensor:129]: 'Apparent Power' >> 72.3 VA
[13:34:23.270][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:23.270][D][sensor:129]: 'Power' >> 46.5 W
[13:34:23.270][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:23.270][D][sensor:129]: 'Current' >> 0.29 A
[13:34:23.271][D][cse7766:181]: Impossible reactive power: -28.6433 is negative
[13:34:23.272][D][cse7766:192]: Impossible power factor: 2.6044 not in interval [0, 1]
[13:34:23.480][D][cse7766:181]: Impossible reactive power: -28.6433 is negative
[13:34:23.480][D][cse7766:192]: Impossible power factor: 2.6044 not in interval [0, 1]
[13:34:23.480][D][cse7766:181]: Impossible reactive power: -28.6433 is negative
[13:34:23.483][D][cse7766:192]: Impossible power factor: 2.6044 not in interval [0, 1]
[13:34:23.790][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:23.791][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:24.263][D][sensor:129]: 'Reactive Power' >> 0.0 var
[13:34:24.263][D][sensor:129]: 'Apparent Power' >> 5.4 VA
[13:34:24.264][D][sensor:129]: 'Power' >> 46.5 W
[13:34:24.267][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:24.267][D][sensor:129]: 'Current' >> 0.00 A
[13:34:24.267][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:24.268][D][sensor:129]: 'Voltage' >> 246.0 V
[13:34:24.268][D][sensor:129]: 'Power Factor' >> nan
[13:34:24.843][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:24.846][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:25.257][D][sensor:129]: 'Current' >> 0.00 A
[13:34:25.258][D][sensor:129]: 'Voltage' >> 244.0 V
[13:34:25.261][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:25.261][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:25.901][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:25.905][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:26.262][D][sensor:129]: 'Current' >> 0.00 A
[13:34:26.262][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:26.265][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:26.266][D][sensor:129]: 'Voltage' >> 244.0 V
[13:34:26.942][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:26.945][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:27.266][D][sensor:129]: 'Current' >> 0.00 A
[13:34:27.267][D][sensor:129]: 'Voltage' >> 244.0 V
[13:34:27.269][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:27.270][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:27.992][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:27.997][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:28.268][D][sensor:129]: 'Current' >> 0.00 A
[13:34:28.268][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:28.271][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:28.273][D][sensor:129]: 'Voltage' >> 244.0 V
[13:34:29.042][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:29.045][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:29.267][D][sensor:129]: 'Current' >> 0.00 A
[13:34:29.267][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:29.271][D][sensor:129]: 'Voltage' >> 244.0 V
[13:34:29.271][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:30.098][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:30.101][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:30.267][D][sensor:129]: 'Current' >> 0.00 A
[13:34:30.268][D][sensor:129]: 'Voltage' >> 246.2 V
[13:34:30.272][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:30.272][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:31.145][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:31.149][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:31.268][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:31.268][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:31.273][D][sensor:129]: 'Current' >> 0.00 A
[13:34:31.274][D][sensor:129]: 'Voltage' >> 246.2 V
[13:34:31.418][D][sensor:129]: 'Uptime Sensor' >> 181 s
[13:34:32.268][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:32.268][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:32.268][D][sensor:129]: 'Voltage' >> 246.2 V
[13:34:32.271][D][sensor:129]: 'Current' >> 0.00 A
[13:34:32.271][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:32.272][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:32.826][D][sensor:129]: 'WiFi Signal dB' >> -39 dBm
[13:34:32.827][D][sensor:129]: 'WiFi Signal Percent' >> 100 %
[13:34:33.253][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:33.257][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:33.272][D][sensor:129]: 'Current' >> 0.00 A
[13:34:33.272][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:33.275][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:33.276][D][sensor:129]: 'Voltage' >> 245.6 V
[13:34:33.695][D][text_sensor:119]: 'Uptime' >> '3m 0s'
[13:34:34.271][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:34.271][D][sensor:129]: 'Voltage' >> 245.5 V
[13:34:34.271][D][sensor:129]: 'Current' >> 0.00 A
[13:34:34.276][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:34.293][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:34.293][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:35.270][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:35.271][D][sensor:129]: 'Current' >> 0.00 A
[13:34:35.271][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:35.274][D][sensor:129]: 'Voltage' >> 245.5 V
[13:34:35.342][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:35.342][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:36.272][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:36.272][D][sensor:129]: 'Current' >> 0.00 A
[13:34:36.272][D][sensor:129]: 'Voltage' >> 244.6 V
[13:34:36.276][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:36.395][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:36.395][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:37.272][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:37.272][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:37.272][D][sensor:129]: 'Current' >> 0.00 A
[13:34:37.277][D][sensor:129]: 'Voltage' >> 244.6 V
[13:34:37.449][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:37.450][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:38.273][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:38.274][D][sensor:129]: 'Current' >> 0.00 A
[13:34:38.274][D][sensor:129]: 'Voltage' >> 244.6 V
[13:34:38.277][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:38.500][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:38.500][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:39.277][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:39.277][D][sensor:129]: 'Voltage' >> 244.9 V
[13:34:39.277][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:39.281][D][sensor:129]: 'Current' >> 0.00 A
[13:34:39.551][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:39.551][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:40.284][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:40.285][D][sensor:129]: 'Power' >> 0.0 W
There are similar errors about impossible reactive power and power factor earlier in the logs, when the sensor was being updated properly (or at least seemed to be) - just after the device started taking power:
[13:34:07.236][D][sensor:129]: 'Power' >> 0.0 W
[13:34:07.236][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:07.239][D][sensor:129]: 'Reactive Power' >> 0.0 var
[13:34:07.239][D][sensor:129]: 'Current' >> 0.00 A
[13:34:07.244][D][sensor:129]: 'Power Factor' >> 1.00
[13:34:07.245][D][sensor:129]: 'Voltage' >> 240.0 V
[13:34:07.245][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:07.608][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:07.919][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:07.920][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:07.920][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.028][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:08.029][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:08.029][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.237][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.237][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:08.237][D][sensor:129]: 'Current' >> 0.00 A
[13:34:08.241][D][sensor:129]: 'Voltage' >> 240.0 V
[13:34:08.242][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:08.242][D][sensor:129]: 'Power Factor' >> 1.00
[13:34:08.242][D][sensor:129]: 'Power' >> 4.9 W
[13:34:08.244][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:08.244][D][sensor:129]: 'Reactive Power' >> 0.0 var
[13:34:08.244][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.453][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.454][D][cse7766:181]: Impossible reactive power: -7.3814 is negative
[13:34:08.765][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:08.765][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:08.765][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.003][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.004][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.083][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:09.086][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:09.087][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.187][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.235][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:09.235][D][sensor:129]: 'Apparent Power' >> 0.0 VA
[13:34:09.236][D][sensor:129]: 'Power' >> 10.3 W
[13:34:09.238][D][sensor:129]: 'Total Energy Since Boot' >> 0.036 kWh
[13:34:09.239][D][sensor:129]: 'Reactive Power' >> 0.0 var
[13:34:09.239][D][sensor:129]: 'Power Factor' >> nan
[13:34:09.240][D][sensor:129]: 'Current' >> 0.00 A
[13:34:09.240][D][sensor:129]: 'Voltage' >> 240.2 V
[13:34:09.289][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.528][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.528][D][cse7766:181]: Impossible reactive power: -11.4914 is negative
[13:34:09.608][D][cse7766:181]: Impossible reactive power: -13.9673 is negative
[13:34:09.613][D][cse7766:192]: Impossible power factor: 1.8336 not in interval [0, 1]
[13:34:09.716][D][cse7766:181]: Impossible reactive power: -13.9673 is negative
[13:34:09.716][D][cse7766:192]: Impossible power factor: 1.8336 not in interval [0, 1]
[13:34:10.053][D][cse7766:181]: Impossible reactive power: -13.9673 is negative
[13:34:10.053][D][cse7766:192]: Impossible power factor: 1.8336 not in interval [0, 1]
[13:34:10.131][D][sensor:129]: 'Energy' >> 0.000 kWh
[13:34:10.134][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:10.237][D][sensor:129]: 'Total Energy' >> 2.196 kWh
[13:34:10.238][D][sensor:129]: 'Reactive Power' >> 7.3 var
[13:34:10.245][D][sensor:129]: 'Current' >> 0.10 A
[13:34:10.245][D][sensor:129]: 'Voltage' >> 240.3 V
[13:34:10.245][D][sensor:129]: 'Power Factor' >> 0.58
[13:34:10.245][D][sensor:129]: 'Apparent Power' >> 23.1 VA
[13:34:10.245][D][sensor:129]: 'Power' >> 24.3 W
I don’t see on your logs when you turn off the power. First line is 13:34:22, last line with some power is 13:34:23, one second later.
I’m not familiar with cse7766 component, but sounds weird it’s telling that reactive power can’t be negative. It’s negative for capacitive loads and positive for inductive loads…
The problem I have is when the device connected to the smart plug turns off. It’s not about the smart plug turning off, therefore naturally there’s no explicit turning off in the logs.
In this test, I used a phone charger and simply physically unplugged it. The power sensor was being updated every second all the time until 13:34:23, then there are no updates until 13:34:40. So I’m quite positive that I unplugged the device somewhere around 13:34:23.
If you need me to be more precise, I can try again, but it’s a bit hard to look at the log that’s speeding while I’m unplugging the device
Looking at the logs, I’m wondering if maybe I should use apparent power instead of power, as that seems to be updated properly. I had that sensor disabled in HA, so I wasn’t aware. I tried this now and indeed I can see the apparent power sensor going down almost immediately after I unplug the device from the plug, while power freezes for several seconds.
I see…
I was following just current reading.
So the negative reactive power puts cse7766 in tilt, I don’t think I can offer solution for that here. Follow the behaviour and report for bug.
Following apparent power doesn’t make sense, it can be twice the real power.
Should work too. That’s actually interesting, checking the full logs again, I can see that current (and apparent power) react to the initial turning on the load whole 2 seconds later than the power sensor. They are not frozen, just reporting 0s, when the power sensor already started reporting some power. Alright, so I guess I’ll use power for turning on tracking and current for turning off.
I have some Athom V2 plugs and they are functioning as I would expect. With the log running I see regular updates at my 10s interval with the lamp off, then on, then off again. On the history graph only state changes are recorded during lamp on when the power has slight fluctuations. I haven’t looked at this code for some time. I see that I have applied a fix for CSE7766 issues, I use “update_interval” instead of “sensor_update_interval”, and filtering the power for low draw to zero.
Not sure if this helps with your issue.
# Fix for https://github.com/esphome/issues/issues/5501 and 5504
external_components:
- source: github://pr#6265
components: [ cse7766 ]
sensor:
- platform: cse7766
update_interval: 10s
power:
name: "Power"
id: power_sensor
accuracy_decimals: 1
filters:
- lambda: if (x < 3.0) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected
state_class: ''