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

 找回密码
 立即注册
查看: 368|回复: 0

[求助] node-red代码向mqtt发送switch,homeassistant不能更改状态

[复制链接]

7

主题

15

帖子

82

积分

注册会员

Rank: 2

积分
82
金钱
67
HASS币
0
发表于 2023-12-23 14:51:20 | 显示全部楼层 |阅读模式
本帖最后由 hunl0613 于 2023-12-23 15:23 编辑
msg.payload={  
   "name":"38度开关",  
   "command_topic": "homeassistant/switch/wanghe_switch_38/set",  
   "state_topic":"homeassistant/switch/wanghe_switch_38/state",
   "unique_id":"wh101",
   "device":{  
      "identifiers":[  
         "wanghe101"  
      ],  
      "name":"热水器"  
      
   },
   "payload_on": "ON",
   "payload_off": "OFF",
   "state_on": "ON",
   "state_off": "OFF",
   "qos": 0,
   "retain": true,
   "command_on_template": "ON",
   "command_off_template": "OFF",
   "state_on_template": "ON",
   "state_off_template": "OFF",
   "value_template": "{{ value_json.state }}"
}
msg.topic = "homeassistant/switch/wanghe_switch_38/config";
msg.retain = true; // 保留配置主题
return msg;



请问上面node-red代码向mqtt发送switch,发送ON或OFF到homeassistant/switch/wanghe_switch_38/state主题可以更改状态,但在homeassistant中mqtt生成的switch中没法点击更改状态,添加代码   "optimistic": true后可以更改状态,但显示的开关样式为turn而不是switch,
2.png
请问如何解决让按钮可以更改状态并样式为switch

flows .rar (1.46 KB, 下载次数: 0)



回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 19:40 , Processed in 0.087508 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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