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

 找回密码
 立即注册
查看: 6045|回复: 4

[经验分享] 用自动化,脚本和input做的空调定时开关的功能

[复制链接]

6

主题

70

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
248
HASS币
0
发表于 2019-8-1 16:40:50 | 显示全部楼层 |阅读模式
本帖最后由 heize 于 2019-8-1 16:44 编辑

不知道还有没有更好的实现方法,刚开始研究ha。。把代码放上来大家讨论:
微信图片_20190801163848.png config的代码
input_number:
  inputnumberacup:
    name: Ac Up
    min: 18
    max: 30
    step: 0.1
    mode: box
  inputnumberacdown:
    name: Ac Down
    min: 18
    max: 30
    step: 0.1
    mode: box
  inputnumberacsleep:
    name: Ac Sleep Mins
    min: 1
    max: 300
    step: 1
    mode: box
  inputnumberacwork:
    name: Ac Work Mins
    min: 1
    max: 300
    step: 1
    mode: box
input_select:
  ac_status:
    options:
      - "PowerOff"
      - "AlwaysPowerOn"
      - "WorkByTime"


animotion的代码
- id: '1535341147667' #操作空调
  alias: OperateAC
  trigger:
    platform: state
    entity_id: input_select.ac_status
  action:
    service_template: >
      {% if is_state('input_select.ac_status', 'PowerOff') %}
      script.1546858112701
      {% elif is_state('input_select.ac_status', 'AlwaysPowerOn') %}
      script.1546858112702
      {% elif is_state('input_select.ac_status', 'WorkByTime') %}
      script.1546858112703
      {% elif is_state('input_select.ac_status', 'WorkByTemp') %}
      script.1546858112706
      {% endif %}
- id: '1535341147668'
  alias: ACPowerToOn
  trigger:
  - above: 0
    entity_id: sensor.temperature_158d00020ffc2e
    platform: numeric_state
    value_template: '{{ state.state | float - states("input_number.inputnumberacup") | float }}'
  action:
    service: script.1546858112706
- id: '1535351943696'
  alias: ACPowerToOff
  trigger:
  - above: 0
    entity_id: sensor.temperature_158d00020ffc2e
    platform: numeric_state
    value_template: '{{ states("input_number.inputnumberacdown") | float -state.state | float }}'
  action:
    service: script.1546858112707
script代码:
'1546858112701':
  alias: ACPowerOff
  sequence:
  - data:
      command: FE00000000000000000000000008008C22B40037004200A401C1038407D20FA61388431210101012101010121010121010101010101010101010101010101012101210101210151010101010101010101010101012101010101010101010101010101010121210164312101010121010101210101210101010101010101010101010101010121212101012101510101010101000000000000000000000000000000200000000000000020002000746
      entity_id: climate.bedroomairconditioningcompanion
    service: climate.xiaomi_miio_send_command
  - data:
      entity_id: automation.acpowertoon
    service: automation.turn_off
  - data:
      entity_id: automation.acpowertooff
    service: automation.turn_off
'1546858112702':
  alias: ACPowerOn
  sequence:
  - data:
      command: FE00000000000000000000000007008C22B3003B00AB01C7037E07DA0FB113883201000001010000000100000100000000000000000000000000000000010001000001000400000000000000000000000000010000000000000000000000000000000101010532010000010100000001000001000000000000000000000000000000000101010000010004000000000000000000000000000000000000000001000000000000000100010106FB
      entity_id: climate.bedroomairconditioningcompanion
    service: climate.xiaomi_miio_send_command
  - data:
      entity_id: automation.acpowertoon
    service: automation.turn_off
  - data:
      entity_id: automation.acpowertooff
    service: automation.turn_off
'1546858112703': #空调定时开关
  alias: ACPowerOnByTime
  sequence:
  - condition: state
    entity_id: input_select.ac_status
    state: 'WorkByTime'
  - service: script.1546858112702 #on
  - delay:
      minutes: "{{states('input_number.inputnumberacwork') | int }}"
  - service: script.1546858112701 #off
  - delay:
      minutes: "{{states('input_number.inputnumberacsleep') | int }}"
  - service: script.1546858112705 #enter
'1546858112705': #空调定时开关复制(为了递归)
  alias: ACPowerOnByTimeClone
  sequence:
  - condition: state
    entity_id: input_select.ac_status
    state: 'WorkByTime'
  - service: script.1546858112702 #on
  - delay:
      minutes: "{{states('input_number.inputnumberacwork') | int }}"
  - service: script.1546858112701 #off
  - delay:
      minutes: "{{states('input_number.inputnumberacsleep') | int }}"
  - service: script.1546858112703 #enter
'1546858112706': #空调按温度开
  alias: ACPowerOnByTemp
  sequence:
  - data:
      entity_id: climate.bedroomairconditioningcompanion
    service: climate.turn_on
  - data:
      command: FE00000000000000000000000007008C22B3003B00AB01C7037E07DA0FB113883201000001010000000100000100000000000000000000000000000000010001000001000400000000000000000000000000010000000000000000000000000000000101010532010000010100000001000001000000000000000000000000000000000101010000010004000000000000000000000000000000000000000001000000000000000100010106FB
      entity_id: climate.bedroomairconditioningcompanion
    service: climate.xiaomi_miio_send_command
  - data:
      entity_id: automation.acpowertoon
    service: automation.turn_off
  - data:
      entity_id: automation.acpowertooff
    service: automation.turn_on
'1546858112707': #空调到温度关
  alias: ACPowerOffByTemp
  sequence:
  - data:
      command: FE00000000000000000000000008008C22B40037004200A401C1038407D20FA61388431210101012101010121010121010101010101010101010101010101012101210101210151010101010101010101010101012101010101010101010101010101010121210164312101010121010101210101210101010101010101010101010101010121212101012101510101010101000000000000000000000000000000200000000000000020002000746
      entity_id: climate.bedroomairconditioningcompanion
    service: climate.xiaomi_miio_send_command
  - data:
      entity_id: automation.acpowertoon
    service: automation.turn_on
  - data:
      entity_id: automation.acpowertooff
    service: automation.turn_off








回复

使用道具 举报

8

主题

736

帖子

4576

积分

论坛元老

Rank: 8Rank: 8

积分
4576
金钱
3835
HASS币
40
QQ
发表于 2019-8-1 17:45:47 | 显示全部楼层
楼主建议你在重新排版一下,下面有点乱
回复

使用道具 举报

7

主题

367

帖子

2119

积分

金牌会员

Rank: 6Rank: 6

积分
2119
金钱
1752
HASS币
0
发表于 2019-8-2 15:15:58 | 显示全部楼层
支持一下  谢谢  分享    小白一个   论坛灌水 学习中
回复

使用道具 举报

8

主题

318

帖子

2172

积分

论坛技术达人

积分
2172
金钱
1844
HASS币
70
发表于 2019-8-2 17:05:56 | 显示全部楼层
支持一下,正好请教这个怎么用啊?
回复

使用道具 举报

31

主题

127

帖子

756

积分

论坛积极会员

积分
756
金钱
629
HASS币
0
发表于 2022-6-20 10:54:52 | 显示全部楼层
这么复杂,这弄的是根据室温调整空调的目标温度和开关吗?
我直接写了6个自动化,分别是空调运行30m,1h,2h,3h,4h,5h后停止,自动化初始状态为假,分个组放到空调按钮下边,想定多久打开对应的自动化。

1.jpg

回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-28 20:55 , Processed in 0.076993 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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