条件:有六个PZEM-004T,但是还少一路。目的:利用现有的传感器对数据进行处理(就是加减运算),虚拟出来一个传感器。
先看效果
从图上可以看到,虚拟出来的功率比较荒谬,竟然是负的。
原因分析:猜测一下可能是和多个传感器的数据更新之间有时间差有关,百度【波特率9600指的是每秒可以传bai输9600个二进制位,也就是9600/8个英文字母的数据量,也就是1200个字节,大约1.2KB】
从这个数据看的话,六个传感器采集一次应该会有600字节的数据,也就是每秒最多更新两次。好吧,我对于这个问题不是太专业,以上仅是盲猜。
结论:虽然对于功率电流之类的瞬时数据误差较大(如果是检测空调等大功率电器这样的误差应该还是可以接受的)。不过用来计算每天的用电量数据应该还可以。
代码分享:
time:
- platform: homeassistant
id: homeassistant_time
i2c:
sda: 2
scl: 15
uart:
rx_pin: 23
tx_pin: 22
baud_rate: 9600
stop_bits: 1
sensor:
- platform: pzemac
current:
name: "PZEM-004T 1 Current"
voltage:
name: "PZEM-004T 1 Voltage"
energy:
name: "PZEM-004T 1 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 1 Power"
id: my_power1
filters:
frequency:
name: "PZEM-004T 1 Frequency"
power_factor:
name: "PZEM-004T 1 Power Factor"
address: 1
update_interval: 0.5s
- platform: pzemac
current:
name: "PZEM-004T 2 Current"
voltage:
name: "PZEM-004T 2 Voltage"
energy:
name: "PZEM-004T 2 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 2 Power"
id: my_power2
frequency:
name: "PZEM-004T 2 Frequency"
power_factor:
name: "PZEM-004T 2 Power Factor"
address: 2
update_interval: 0.5s
- platform: pzemac
current:
name: "PZEM-004T 3 Current"
voltage:
name: "PZEM-004T 3 Voltage"
energy:
name: "PZEM-004T 3 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 3 Power"
id: my_power3
frequency:
name: "PZEM-004T 3 Frequency"
power_factor:
name: "PZEM-004T 3 Power Factor"
address: 3
update_interval: 0.5s
- platform: pzemac
current:
name: "PZEM-004T 4 Current"
voltage:
name: "PZEM-004T 4 Voltage"
energy:
name: "PZEM-004T 4 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 4 Power"
id: my_power4
filters:
frequency:
name: "PZEM-004T 4 Frequency"
power_factor:
name: "PZEM-004T 4 Power Factor"
address: 4
update_interval: 0.5s
- platform: pzemac
current:
name: "PZEM-004T 5 Current"
voltage:
name: "PZEM-004T 5 Voltage"
energy:
name: "PZEM-004T 5 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 5 Power"
id: my_power5
frequency:
name: "PZEM-004T 5 Frequency"
power_factor:
name: "PZEM-004T 5 Power Factor"
address: 5
update_interval: 0.5s
- platform: pzemac
current:
name: "PZEM-004T 6 Current"
voltage:
name: "PZEM-004T 6 Voltage"
energy:
name: "PZEM-004T 6 Energy"
filters:
- multiply: 0.001
unit_of_measurement: Kwh
power:
name: "PZEM-004T 6 Power"
id: my_power6
frequency:
name: "PZEM-004T 6 Frequency"
power_factor:
name: "PZEM-004T 6 Power Factor"
address: 6
update_interval: 0.5s
- platform: template //只是测试了功率也没有没有修改图标,而且传感器数据更新太快,没进行过滤,不建议直接使用
name: "PZEM-004T 7 Power"
unit_of_measurement: w
lambda: |-
return id(my_power1).raw_state ;
filters:
- lambda: return x * 1.0 - id(my_power2).raw_state - id(my_power3).raw_state - id(my_power4).raw_state - id(my_power5).raw_state - id(my_power6).raw_state ;
update_interval: 0ms
- platform: total_daily_energy
name: "Total Daily 1 Energy"
power_id: my_power1
- platform: total_daily_energy
name: "Total Daily 2 Energy"
power_id: my_power2
- platform: total_daily_energy
name: "Total Daily 3 Energy"
power_id: my_power3
- platform: total_daily_energy
name: "Total Daily 4 Energy"
power_id: my_power4
- platform: total_daily_energy
name: "Total Daily 5 Energy"
power_id: my_power5
- platform: total_daily_energy
name: "Total Daily 6 Energy"
power_id: my_power6
switch:
- platform: restart
name: "power_sensor Restart"
数据过滤throttle/ heartbeat/ debounce/ delta# Example filters:filters: - throttle: 1s - heartbeat: 5s - debounce: 0.1s - delta: 5.0 - lambda: return x * (9.0/5.0) + 32.0;
节流阀:节流输入值。当此过滤器获得输入值时,它将检查最后一个输入值是否至少是旧的。如果它不早于配置的值,则该值不会向前传递。specified time period 心跳:在指定的时间间隔内发送该传感器的最后一个值。因此,10s无论输入值如何,值都会使滤波器每10秒输出一次值。 debounce:仅在最后输入的值至少 旧时才发送值。例如,如果两个值几乎同时输入,则此过滤器仅在指定的时间段过去之后且没有任何新的输入值时,才输出最后一个值。specified time period delta:此过滤器存储通过此过滤器的最后一个值,并且仅在绝对差大于配置的值时才传递输入值。例如,如果首先输入1.0,则会继续传递。如果将增量过滤器的值配置为5,则现在不会传递传入值2.0,而仅传递至少6.0大或-4.0的值。
|