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

 找回密码
 立即注册
查看: 6308|回复: 13

求助大神 间隔型开关的自动化 --简化写法

[复制链接]

8

主题

361

帖子

3775

积分

论坛元老

Rank: 8Rank: 8

积分
3775
金钱
3414
HASS币
10
发表于 2018-9-26 22:07:33 | 显示全部楼层 |阅读模式
动作描述:一个实体开关21:00打开,30分钟后关闭,再30分钟后打开,30分后再关闭,30分后打开。。。。。循环到06:00关闭开关,结束

我这只会用delay,一个个写太复杂了,问问各路大神有没有简化的方法?

写个实例供学习下

再次感谢!
回复

使用道具 举报

17

主题

336

帖子

2477

积分

金牌会员

Rank: 6Rank: 6

积分
2477
金钱
2141
HASS币
0
发表于 2018-9-27 00:13:02 | 显示全部楼层
参考下我的代码吧,鱼缸水泵每小时自动打开关闭,稍微修改即可使用
#鱼缸水泵每1时打开关闭
  - alias: Auto_fish_open
    initial_state: false
    hide_entity: false
    trigger:
      - platform: time
        hours: '/1'
        minutes: 1
        seconds: 0
#    condition:
#      conditions:
#      - condition: time
#        after: '19:00:00'
#        before: '08:30:00'
    action:
      - service: switch.toggle
        entity_id: switch.fish_pump
回复

使用道具 举报

30

主题

493

帖子

4767

积分

论坛元老

佑桑

Rank: 8Rank: 8

积分
4767
金钱
4259
HASS币
156

教程狂人

发表于 2018-9-27 17:49:52 | 显示全部楼层
參考一下我的自動化
1.針對一台電扇, 我設計了一個自然風模式, 每2分鐘亂數決定檔位
2.做了一個到數計時器, 時間到將電扇關閉

自然風
#################################################################################
# 啟動自然風
- alias: auto natural wind for fan in masterbedroom
  hide_entity: true
  initial_state: 'off'
  # 每 2 分鐘觸發一次
  trigger:
    - platform: time
      minutes: /2
      seconds: 0
condition:
    - condition: state
      entity_id: fan.espeasy_aa4cc6
      state: 'on'
  action:
    - service: fan.set_speed
      entity_id: fan.espeasy_aa4cc6
      data_template:
        speed: '{{ (range(2,4) | random ) }}'
#

#################################################################################
# 關閉自然風 當 主臥電扇關閉時
- alias: auto stop natural wind when stop fan in masterbedroom
  hide_entity: true
  trigger:
    - platform: state
      entity_id: fan.espeasy_aa4cc6
      to: 'off'
  action:
    - service: automation.turn_off
      entity_id: automation.auto_natural_wind_for_fan_in_masterbedroom


倒數計時
#################################################################################
# 給 主臥室 使用的倒數計時器
- alias: Timer timer_masterbedroom countdown
  hide_entity: true
  # 每分鐘觸發一次
  trigger:
    - platform: time
      minutes: /1
      seconds: 0
  # 若指定的 entity_id 數值大於 0.5
  condition:
    - condition: numeric_state
      entity_id: input_number.timer_masterbedroom
      above: '0.5'
  # 指定的的 entity_id 數值減 1
  action:
    - service: input_number.set_value
      entity_id: input_number.timer_masterbedroom
      data_template:
        value: '{{ states("input_number.timer_masterbedroom") | int -1 }}'
#################################################################################
# 倒數計時到 0 之後觸發本項自動化
- alias: Timer timer_masterbedroom Stop
  hide_entity: true
  # 若指定的 entity_id 數值小於 0.5
  trigger:
    - platform: numeric_state
      entity_id: input_number.timer_masterbedroom
      below: '0.5'
  # 執行 OOXX
  action:
- service: script.turn_on
      entity_id: script.scp_fan_off_when_timeup_in_masterbedroom

回复

使用道具 举报

8

主题

361

帖子

3775

积分

论坛元老

Rank: 8Rank: 8

积分
3775
金钱
3414
HASS币
10
 楼主| 发表于 2018-9-27 19:30:20 | 显示全部楼层
villen 发表于 2018-9-27 00:13
参考下我的代码吧,鱼缸水泵每小时自动打开关闭,稍微修改即可使用
#鱼缸水泵每1时打开关闭
  - alias: Aut ...

感谢耐心的回复,简单明了,至少能看懂
回复

使用道具 举报

8

主题

361

帖子

3775

积分

论坛元老

Rank: 8Rank: 8

积分
3775
金钱
3414
HASS币
10
 楼主| 发表于 2018-9-27 19:38:00 | 显示全部楼层
chinyaolin 发表于 2018-9-27 17:49
參考一下我的自動化
1.針對一台電扇, 我設計了一個自然風模式, 每2分鐘亂數決定檔位
2.做了一個到數計時器, ...

这个目前对于我这小白感觉还是挺复杂的,但对于有需要的场景是个值得学习的模板,多谢热心的回复
回复

使用道具 举报

9

主题

216

帖子

2060

积分

金牌会员

Rank: 6Rank: 6

积分
2060
金钱
1844
HASS币
20
发表于 2018-9-27 21:39:06 | 显示全部楼层
# 灭蚊器日间循环开闭,开30分钟,关30分钟
# https://www.home-assistant.io/docs/scripts/conditions/
- id: '20180816195000'
  alias: free_mosquito
  initial_state: true
  hide_entity: true
  action:
  - service: switch.turn_on
    entity_id: switch.socket_bl_mos
  - delay: '00:30:00'
  - service: switch.turn_off
    entity_id: switch.socket_bl_mos
  trigger:
    platform: time
    # You can also match on interval. This will match every 60 minutes
    minutes: '/60'
    seconds: 00
  condition:
    condition: time
    # At least one of the following is required.
    after: '06:20:00'
    before: '23:59:00'
回复

使用道具 举报

9

主题

216

帖子

2060

积分

金牌会员

Rank: 6Rank: 6

积分
2060
金钱
1844
HASS币
20
发表于 2018-9-27 21:40:31 | 显示全部楼层
这个和你的需求很相似
回复

使用道具 举报

10

主题

154

帖子

581

积分

高级会员

Rank: 4

积分
581
金钱
427
HASS币
0
发表于 2019-1-31 15:05:31 | 显示全部楼层
学习一下,感谢各位热心的分享
回复

使用道具 举报

0

主题

90

帖子

1070

积分

金牌会员

Rank: 6Rank: 6

积分
1070
金钱
980
HASS币
0
发表于 2019-2-19 22:17:00 | 显示全部楼层
airhog 发表于 2018-9-27 21:39
# 灭蚊器日间循环开闭,开30分钟,关30分钟
# https://www.home-assistant.io/docs/scripts/conditions/
-  ...

这个在新的版本0.87.1里面没办法使用’/60‘报错
回复

使用道具 举报

9

主题

216

帖子

2060

积分

金牌会员

Rank: 6Rank: 6

积分
2060
金钱
1844
HASS币
20
发表于 2019-2-20 22:37:47 | 显示全部楼层
shmily-shmily 发表于 2019-2-19 22:17
这个在新的版本0.87.1里面没办法使用’/60‘报错

旧版
trigger:
    platform: time

新版
trigger:
    platform: time_pattern
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-22 08:30 , Processed in 0.338365 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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