『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 7790|回复: 3

[esphome] 虚拟一路PZEM-004T。

[复制链接]

6

主题

88

帖子

897

积分

高级会员

Rank: 4

积分
897
金钱
809
HASS币
0
发表于 2020-12-7 16:58:04 | 显示全部楼层 |阅读模式
条件:有六个PZEM-004T,但是还少一路。目的:利用现有的传感器对数据进行处理(就是加减运算),虚拟出来一个传感器。
先看效果 N4AU9XHS~JB080MQ0$A2.png



从图上可以看到,虚拟出来的功率比较荒谬,竟然是负的。
原因分析:猜测一下可能是和多个传感器的数据更新之间有时间差有关,百度【波特率9600指的是每秒可以传bai输9600个二进制位,也就是9600/8个英文字母的数据量,也就是1200个字节,大约1.2KB】 U3PT~OR7$DOTXA9T3}_19FK.png 从这个数据看的话,六个传感器采集一次应该会有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的值。



回复

使用道具 举报

11

主题

67

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
251
HASS币
0
发表于 2021-9-17 11:58:37 | 显示全部楼层
请问下线咋接的
回复

使用道具 举报

43

主题

412

帖子

3808

积分

元老级技术达人

积分
3808
金钱
3391
HASS币
136
发表于 2022-6-7 23:29:35 | 显示全部楼层
也正在搞培正,学习一下
回复

使用道具 举报

4

主题

103

帖子

1750

积分

金牌会员

Rank: 6Rank: 6

积分
1750
金钱
1647
HASS币
0
发表于 2022-10-7 17:43:14 | 显示全部楼层
刚好在做多路培正接入,学习下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-29 00:35 , Processed in 0.090150 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表