本帖最后由 ms2 于 2020-5-22 12:07 编辑
在论坛里看到有人用涂鸦APP的热水器可以接入HA,我有一个带功率的涂鸦插座,想着可以调用功率来做一些智能切换(老用DC1,想换个新的玩玩),相关链接如下:
https://bbs.hassbian.com/thread-8543-1-1.html
现在我可以HA接入我的插座了,开关控制也没有问题,在HA的服务里也可以显示相关的电压、电流、功率,如下图:
按道理应该就正常了呀,但怎么搞sensor都输出不了,真是奇怪了,有懂的大哥帮忙看看不?
相关代码如下:
switch:
- platform: localtuya
host: 192.168.1.55
local_key: xxxxxxxxxxx
device_id: xxxxxxxxxx
protocol: 3.3
current: 4
current_consumption: 5
voltage: 6
switches:
some_switch1:
friendly_name: TUYA_SW01
id: 1
sensor:
- platform: template
sensors:
aaaaa:
value_template: >-
{{ states.switch.some_switch1.attributes.current_consumption }}
unit_of_measurement: 'W'
完美解决,感谢热心帮我的朋友 ,结果看后面的回帖传感器的正确写法:
sensor:
- platform: template
sensors:
switch1_voltage:
friendly_name: "电压"
value_template: >-
{{ state_attr('switch.tuya_sw01', 'voltage') |float / 10 }}
unit_of_measurement: 'V'
switch1_current:
friendly_name: "电流"
value_template: >-
{{ state_attr('switch.tuya_sw01', 'current') |float / 100 }}
unit_of_measurement: 'A'
switch1_current_consumption:
friendly_name: "功率"
value_template: >-
{{ state_attr('switch.tuya_sw01', 'current_consumption') |float / 10 }}
unit_of_measurement: 'W'
|