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

 找回密码
 立即注册
查看: 2526|回复: 14

[技术探讨] 请教大佬,如何获取空调的hvac_modes状态?

[复制链接]

7

主题

107

帖子

942

积分

高级会员

Rank: 4

积分
942
金钱
835
HASS币
0
发表于 2023-5-29 20:52:00 | 显示全部楼层 |阅读模式
本帖最后由 kffnqtd 于 2023-6-3 21:54 编辑

夏天到了,家里的空调小孩子经常开着就跑出去玩忘了关。想着用自动化来获取空调的hvac_modes状态然后发送通知到手机,然后远程关闭,节省点电费。
我问了一下GPT,给我的代码是
automation:
  - alias: 监听空调模式变化
    trigger:
      platform: event
      event_type: state_changed
      event_data:
        entity_id: climate.your_ac_entity_id
        event_data:
          attribute: hvac_modes
    action:
      - service: notify.notify_platform
        data_template:
          message: '空调模式已变为 {{ trigger.event.data.new_state.attributes.hvac_modes }}'
但手动执行通知的时候报
执行动作时出错
Error rendering data template: UndefinedError: 'trigger' is undefined
操作空调手机也收不到通知。
有大佬支个招,怎么解决吗?

自动化不知道是不是有BUG,设置好了之后,空调状态没有发生变化,会每分钟执行一次,导致每分钟一个通知,五台空调算下来,手机响个不停
现在转到node-red流程,勉强能用,但是空调打开之后,设置温度变化不会通知,只有运行模式,也是就hvac-mode变化才会通知,有没有大佬知道怎么添加进去吗?
下面是flow流程
[{"id":"dc554414ed86e800","type":"tab","label":"空调状态监控","disabled":false,"info":"","env":[]},{"id":"666eabcbb26df849","type":"server-state-changed","z":"dc554414ed86e800","name":"主卧空调","server":"2616e482.1e92ac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.196812581772705_climate","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":60,"y":160,"wires":[["2392d2f3a851d2cb"]]},{"id":"5e1a88b2028bc124","type":"debug","z":"dc554414ed86e800","name":"debug 22","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":240,"wires":[]},{"id":"a0785f369e7d249f","type":"api-call-service","z":"dc554414ed86e800","name":"","server":"2616e482.1e92ac","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{"message": msg.data.new_state.attributes.friendly_name & msg.payload & msg.data.new_state.attributes.temperature &"°C"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":240,"wires":[["5e1a88b2028bc124"]]},{"id":"2392d2f3a851d2cb","type":"change","z":"dc554414ed86e800","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"关闭","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"cool","fromt":"str","to":"制冷","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"auto","fromt":"str","to":"自动","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"dry","fromt":"str","to":"抽湿","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"heat","fromt":"str","to":"制热","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"fan_only","fromt":"str","to":"送风","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":280,"wires":[["4d1361c0a84faa59","e5e0af3263c066bd"]]},{"id":"fcf556ddc02c448f","type":"server-state-changed","z":"dc554414ed86e800","name":"次卧空调","server":"2616e482.1e92ac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.194613558487692_climate","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":60,"y":220,"wires":[["2392d2f3a851d2cb"]]},{"id":"d26d5174b6a56a03","type":"server-state-changed","z":"dc554414ed86e800","name":"卧室空调","server":"2616e482.1e92ac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.194613558488256_climate","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":60,"y":280,"wires":[["2392d2f3a851d2cb"]]},{"id":"b9f5850699f806f0","type":"server-state-changed","z":"dc554414ed86e800","name":"阳光房空调","server":"2616e482.1e92ac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.188016489061058_climate","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":60,"y":340,"wires":[["2392d2f3a851d2cb"]]},{"id":"dbbd05ec229c03a6","type":"server-state-changed","z":"dc554414ed86e800","name":"客厅空调","server":"2616e482.1e92ac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.gr_acunit_6400_02_563c","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":60,"y":400,"wires":[["2392d2f3a851d2cb"]]},{"id":"4d1361c0a84faa59","type":"switch","z":"dc554414ed86e800","name":"打开","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"关闭","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":240,"wires":[["a0785f369e7d249f"]]},{"id":"e5e0af3263c066bd","type":"switch","z":"dc554414ed86e800","name":"关闭","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"关闭","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":320,"wires":[["eef2914ef7c151c6"]]},{"id":"eef2914ef7c151c6","type":"api-call-service","z":"dc554414ed86e800","name":"","server":"2616e482.1e92ac","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{"message": msg.data.new_state.attributes.friendly_name & msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":320,"wires":[[]]},{"id":"2616e482.1e92ac","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
截屏2023-06-03 21.51.18.png
回复

使用道具 举报

5

主题

471

帖子

2114

积分

金牌会员

Rank: 6Rank: 6

积分
2114
金钱
1643
HASS币
0
发表于 2023-5-29 22:09:10 | 显示全部楼层
本帖最后由 hyq 于 2023-5-29 22:14 编辑

我是直接写自动化。没人就自动关闭。目前只是写了空调扇的!空调还没写。反正家里各种传感器那么多。我连不关门就要自动关闭。之前用nr就是那样弄的,现在自动化全部转移到HA目前空调还没用就还没写。
回复

使用道具 举报

7

主题

107

帖子

942

积分

高级会员

Rank: 4

积分
942
金钱
835
HASS币
0
 楼主| 发表于 2023-5-30 19:22:06 | 显示全部楼层
hyq 发表于 2023-5-29 22:09
我是直接写自动化。没人就自动关闭。目前只是写了空调扇的!空调还没写。反正家里各种传感器那么多。我连不 ...

家里还没添置其它传感器,只能手动监控了。
回复

使用道具 举报

5

主题

471

帖子

2114

积分

金牌会员

Rank: 6Rank: 6

积分
2114
金钱
1643
HASS币
0
发表于 2023-5-30 21:58:26 | 显示全部楼层
kffnqtd 发表于 2023-5-30 19:22
家里还没添置其它传感器,只能手动监控了。

那就没办法了!我是按我的生活习惯。全部自动化控制。需要手动或者语音控制的很少!
回复

使用道具 举报

1

主题

24

帖子

253

积分

中级会员

Rank: 3Rank: 3

积分
253
金钱
229
HASS币
0
发表于 2023-6-1 12:59:14 | 显示全部楼层
空调的hvac_modes是所有支持的模式列表。当前空调的状态就是state
trigger:
    platform: state
    entity_id: climate.ac_entity_id
action:
    - service: notify.notify_platform
      data_template:
        message: "{{ states('climate.ac_entity_id') }}"
回复

使用道具 举报

1

主题

65

帖子

357

积分

中级会员

Rank: 3Rank: 3

积分
357
金钱
292
HASS币
0
发表于 2023-6-1 14:39:01 | 显示全部楼层
获取实体状态  {{states('fan.broan')}}
获取实体属性  {{state_attr('fan.broan', 'icon')}}
回复

使用道具 举报

7

主题

107

帖子

942

积分

高级会员

Rank: 4

积分
942
金钱
835
HASS币
0
 楼主| 发表于 2023-6-1 22:38:59 | 显示全部楼层
heculess 发表于 2023-6-1 12:59
空调的hvac_modes是所有支持的模式列表。当前空调的状态就是state

感谢大佬指点,方法是实现了,但自动化好像每分钟都会执行一次,空调没有动过。要怎么设置才能达到,只要空调的状态发生变化才通知?其它变化也可以,调整了温度,或者打开了节能模式之类的。
回复

使用道具 举报

7

主题

107

帖子

942

积分

高级会员

Rank: 4

积分
942
金钱
835
HASS币
0
 楼主| 发表于 2023-6-1 22:42:40 | 显示全部楼层
jeelinbear 发表于 2023-6-1 14:39
获取实体状态  {{states('fan.broan')}}
获取实体属性  {{state_attr('fan.broan', 'icon')}}

想请教一下,假如我想要把摄氏度符号℃加入,应该怎么写呢?
{{state_attr('climate.your_ac_entity_id', 'temperature')}}
回复

使用道具 举报

1

主题

65

帖子

357

积分

中级会员

Rank: 3Rank: 3

积分
357
金钱
292
HASS币
0
发表于 2023-6-2 10:47:11 | 显示全部楼层
kffnqtd 发表于 2023-6-1 22:42
想请教一下,假如我想要把摄氏度符号℃加入,应该怎么写呢?
{{state_attr('climate.your_ac_entity_id', ...

加单位要再接两行定义单位

state_class: measurement
unit_of_measurement: "℃"
回复

使用道具 举报

7

主题

107

帖子

942

积分

高级会员

Rank: 4

积分
942
金钱
835
HASS币
0
 楼主| 发表于 2023-6-3 22:47:51 | 显示全部楼层
jeelinbear 发表于 2023-6-2 10:47
加单位要再接两行定义单位

state_class: measurement

换node red来通知了。但是不知道如果我设置了空调的温度,不知道怎么通知。
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-27 12:47 , Processed in 0.091746 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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