『HomeAssistant』求助&解答专区

[已解决] 涂鸦智能插座带功率,接入了本地涂鸦,但功率调用不出来
  • 楼主 ms2
  • 85648602020-5-20 17:54:44
本帖最后由 ms2 于 2020-5-22 12:07 编辑

在论坛里看到有人用涂鸦APP的热水器可以接入HA,我有一个带功率的涂鸦插座,想着可以调用功率来做一些智能切换(老用DC1,想换个新的玩玩),相关链接如下:
https://bbs.hassbian.com/thread-8543-1-1.html

现在我可以HA接入我的插座了,开关控制也没有问题,在HA的服务里也可以显示相关的电压、电流、功率,如下图:
微信图片_20200520174948.png

按道理应该就正常了呀,但怎么搞sensor都输出不了,真是奇怪了,有懂的大哥帮忙看看不?
微信图片_202005201749481111.png
相关代码如下:
  1. switch:
  2.   - platform: localtuya
  3.     host: 192.168.1.55
  4.     local_key: xxxxxxxxxxx
  5.     device_id: xxxxxxxxxx
  6.     protocol: 3.3
  7.     current: 4
  8.     current_consumption: 5
  9.     voltage: 6
  10.     switches:
  11.       some_switch1:
  12.         friendly_name: TUYA_SW01
  13.         id: 1

  14. sensor:
  15.   - platform: template
  16.     sensors:
  17.       aaaaa:
  18.         value_template: >-
  19.           {{ states.switch.some_switch1.attributes.current_consumption }}
  20.         unit_of_measurement: 'W'
复制代码

完美解决,感谢热心帮我的朋友 ,结果看后面的回帖传感器的正确写法:
  1. sensor:
  2.   - platform: template
  3.     sensors:
  4.       switch1_voltage:
  5.         friendly_name: "电压"
  6.         value_template: >-
  7.           {{ state_attr('switch.tuya_sw01', 'voltage') |float / 10 }}
  8.         unit_of_measurement: 'V'
  9.       switch1_current:
  10.         friendly_name: "电流"
  11.         value_template: >-
  12.           {{ state_attr('switch.tuya_sw01', 'current') |float / 100 }}
  13.         unit_of_measurement: 'A'
  14.       switch1_current_consumption:
  15.         friendly_name: "功率"
  16.         value_template: >-
  17.           {{ state_attr('switch.tuya_sw01', 'current_consumption') |float / 10 }}
  18.         unit_of_measurement: 'W'
复制代码

微信图片_20200520174948.png



评分

倒序浏览 看全部 全部回复60
  • 沙发 ms2
  • 2020-5-20 17:56:22
本帖最后由 ms2 于 2020-5-20 17:57 编辑

仔细看了又看,这相当正确呀,按理说在服务里者显示了功率的值了,只要做一个sensors调出来就行了,没有哪里有问题呀,就是sensors取不到数值,真是奇怪了。
改成這種寫法?
value_template: "{{ state_attr('switch.plug_158d000283955b', 'power_consumed') }}"
本帖最后由 情非殇 于 2020-5-20 19:52 编辑

https://www.home-assistant.io/integrations/template/
  • 5# ms2
  • 2020-5-20 23:15:26
jasonlai79 发表于 2020-5-20 19:33
改成這種寫法?
value_template: "{{ state_attr('switch.plug_158d000283955b', 'power_consumed') }}" ...

https://github.com/fastcolors/localtuya-homeassistant/blob/master/README.md    我是按这插件作者的标准写的呀
  • 6# ms2
  • 2020-5-20 23:20:31
jasonlai79 发表于 2020-5-20 19:33
改成這種寫法?
value_template: "{{ state_attr('switch.plug_158d000283955b', 'power_consumed') }}" ...

明天试试你说的写法
  • 7# ms2
  • 2020-5-21 10:06:51
jasonlai79 发表于 2020-5-20 19:33
改成這種寫法?
value_template: "{{ state_attr('switch.plug_158d000283955b', 'power_consumed') }}" ...

还是不行呀,改成这样:
  1. sensor:
  2.   - platform: template
  3.     sensors:
  4.       aaaaa:
  5.         value_template: "{{ state_attr('switch.some_switch1', 'voltage') }}"
  6.         unit_of_measurement: 'W'
复制代码

不显示   未知     了,显示:None W      了
  • 8# ms2
  • 2020-5-21 10:10:38
情非殇 发表于 2020-5-20 19:47
https://www.home-assistant.io/integrations/template/

还是不行,不显示   未知     了,显示:None W      了
ms2 发表于 2020-5-21 10:10
还是不行,不显示   未知     了,显示:None W      了

你在開發工具裡的模板可以正常顯示嗎?
  • 10# ms2
  • 2020-5-21 18:06:29
jasonlai79 发表于 2020-5-21 12:17
你在開發工具裡的模板可以正常顯示嗎?

可以,我的帖子有发图,电压,电流跟功率都能显示
1234.. 7下一页
回复 28收藏