本帖最后由 a2633063 于 2020-4-14 14:01 编辑
对于zA1 之前使用的ha配置是用一个number input作为触发,配合自动化来完成对zA1的风速控制,这样用到3个自动化1个input 1个开关 很麻烦
研究了下hass的mqtt fan 改为此接入,代码如下:
需要将MACMAC 替换为设备的小写mac地址(如1234567890ab )
md格式下代码竟然出现一些符号被替换的问题.所以把配置贴在最后...
能够控制,但是并不完美,:
fan的风扇控制不能像拖动滚动条一样来配置,只能阶梯式配置.使用一个speed的列表来.默认可以配置low medium high ,
同时也可以直接用字符串来表示发送的命令{"mac":"MACMAC","speed":80} ,但是用字符串时在使用时列表里显示的也是这一串字符,对使用很不友好.
之后我又尝试了{"mac":"MACMAC","speed":30} (此处不用引号括起来),控制也有效,但是列表显示变成了[object Object]
求教大佬,如何使命令有效的情况下,能使列表显示为需要的自定义内容?
fan:
- platform: mqtt
name: 'za1_MACMAC'
state_topic: "device/za1/MACMAC/state"
command_topic: "device/za1/MACMAC/set"
state_value_template: >
{%- if value_json.on == 0 -%}
{"mac":"MACMAC","on":0}
{%- else -%}
{"mac":"MACMAC","on":1}
{%- endif -%}
speed_state_topic: "device/za1/MACMAC/state"
speed_command_topic: "device/za1/MACMAC/set"
speed_value_template: >
{%- if value_json.speed < 25 -%}
{"mac":"MACMAC","speed":10}
{%- elif value_json.speed < 75 -%}
{"mac":"MACMAC","speed":50}
{%- else -%}
{"mac":"MACMAC","speed":100}
{%- endif -%}
qos: 0
payload_on: '{"mac":"MACMAC","on":1}'
payload_off: '{"mac":"MACMAC","on":0}'
payload_low_speed: '{"mac":"MACMAC","speed":10}'
payload_medium_speed: '{"mac":"MACMAC","speed":50}'
payload_high_speed: '{"mac":"MACMAC","speed":100}'
speeds:
- low
- medium
- high
- '{"mac":"MACMAC","speed":80}'
- {"mac":"MACMAC","speed":30}
homeassistant:
customize:
fan.za1_MACMAC:
friendly_name: zA1空气净化器
|