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

 找回密码
 立即注册
楼主: 情非殇

[新奇玩法] 易用版-延迟倒计时的通用定时器卡片

  [复制链接]

10

主题

145

帖子

1619

积分

论坛技术达人

积分
1619
金钱
1469
HASS币
30
发表于 2023-5-17 17:52:56 | 显示全部楼层
本帖最后由 hunl1986 于 2023-5-17 19:02 编辑

终于搞定,原来climate.set_operation_mode服务不能用,要改为climate.set_hvac_mode,新版本原来的代码不能用。
把代码给大家看看

## 倒计时通用面板
homeassistant:
  customize:
    sensor.timer_setting:
      friendly_name: 设置延迟时间
      icon: mdi:timer
    input_number.timer_hour:
      friendly_name: 时
      icon: mdi:timer
    input_number.timer_min:
      friendly_name: 分
      icon: mdi:timer
    input_number.timer_sec:
      friendly_name: 秒
      icon: mdi:timer
      # hidden: true
    timer.timer:
      friendly_name: 延迟倒计时
      icon: mdi:timer
    script.timer_start:
      friendly_name: 开始倒计时
      icon: mdi:timer
    script.timer_cancel:
      friendly_name: 取消倒计时
      icon: mdi:timer-off
    

input_select:
  timer_climate:
    name: 延时关闭空调
    options:
      - 选择空调
      - 客厅空调
      - 主卧空调
      - 次卧空调
      - 客卧空调
    initial: '选择空调'
    icon: mdi:format-list-checkbox #select-all #toggle-switch-off
  timer_switch:
    name: 延时关闭设备
    options:
      - 选择设备
      - 客厅大灯
      - 客厅餐灯
      - 未定义8
      - 未定义9
      - 未定义0
    initial: '选择设备'
    icon: mdi:format-list-checkbox #select-all #toggle-switch-off
  timer_state:
    name: 操作
    options:
      - 开
      - 关
    initial: '关'
    icon: mdi:light-switch #nintendo-switch

sensor:
  - platform: template
    sensors:
      timer_setting:
        friendly_name: 'Time'
        value_template: '{{ "%0.02d:%0.02d:%0.02d" | format(states("input_number.timer_hour") | int, states("input_number.timer_min") | int, states("input_number.timer_sec") | int) }}'

input_number:
  timer_hour:
    name: TimerHour
    # icon: mdi:timer
    # initial: 00
    min: 0
    max: 23
    step: 1
  timer_min:
    name: TimerMinute
    # icon: mdi:timer
    # initial: 00
    min: 0
    max: 59
    step: 1
  timer_sec:
    name: TimerSecond
    # icon: mdi:timer
    initial: 00
    min: 0
    max: 59
    step: 1

timer:
  timer:
    duration: '00:00:00'

script:
  timer_start:
    sequence:
      service: timer.start
      data_template: 
        entity_id: timer.timer
        duration: >
          {{ states("sensor.timer_setting") }}  
  timer_cancel:
    sequence:
      service: timer.cancel
      entity_id: timer.timer

group:
  timer_switch:
    name: 通用延时器
    entities:
      - input_select.timer_climate
      - input_select.timer_switch
      - input_select.timer_state
      - sensor.timer_setting
      - input_number.timer_hour
      - input_number.timer_min
      - input_number.timer_sec
      - timer.timer
      - script.timer_start
      - script.timer_cancel

# binary_sensor:
#   - platform: platform: state
#     name: timer_climate
#     entity_id: input_select.timer_climate
#     payload_on: "Select Input"
#   - platform: platform: state
#     name: timer_switch
#     entity_id: input_select.timer_switch
#     payload_on: "Select Input"

automation:
  - alias: number_timer
    hide_entity: true
    trigger:
      - platform: state
        entity_id: sensor.timer_setting
    action:
      service: timer.start
      data_template: 
        entity_id: timer.timer
        duration: >
          {{ states("sensor.timer_setting") }}
  - alias: empty_timer
    hide_entity: true
    trigger:
      - platform: state
        entity_id: input_select.timer_climate
      - platform: state
        entity_id: input_select.timer_switch
      - platform: state
        entity_id: input_select.timer_state
    action:
      - service: timer.cancel
        entity_id: timer.timer
      # - service: timer.start
      #   data_template: 
      #     entity_id: timer.timer
      #     duration: >
      #       {{ states("sensor.timer_setting") }}
  - alias: timer_climate_delay
    hide_entity: true
    trigger: 
      platform: event
      event_type: timer.finished
      event_data: 
        entity_id: timer.timer
    action: 
      - service: climate.set_hvac_mode
        data_template:
          entity_id: >-
            {% if is_state("input_select.timer_climate", "客厅空调") %}
              climate.mqtt_34ea344dd13c
            {% elif is_state("input_select.timer_climate", "主卧空调") %}
              climate.mqtt_34ea3496151c
            {% elif is_state("input_select.timer_climate", "次卧空调") %}
              climate.entity_id3
            {% elif is_state("input_select.timer_climate", "客卧空调") %}
              climate.entity_id4
            {% endif %}
          hvac_mode: 'off' 
          #hvac_mode后面要改为自己控制的关闭代码,在开发者工具-服务可以看到
      - service: input_select.select_option
        data:
          entity_id: input_select.timer_climate
          option: "选择空调"
  - alias: timer_switch_turnon
    hide_entity: true
    trigger:
      platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.timer
    condition:
      condition: state
      entity_id: input_select.timer_state
      state: '开'    
    action:
      - service: homeassistant.turn_on
        data_template:
          entity_id: >-
            {% if is_state("input_select.timer_switch", "客厅大灯") %}
              light.fsl002_cloud_646808
            {% elif is_state("input_select.timer_switch", "客厅餐灯") %}
              light.wy0b01_cloud_056917
            {% elif is_state("input_select.timer_switch", "未定义8") %}
              switch.entity_id8
            {% elif is_state("input_select.timer_switch", "未定义9") %}
              switch.entity_id9
            {% elif is_state("input_select.timer_switch", "未定义0") %}
              switch.entity_id0
            {% endif %}
      - service: input_select.select_option
        data:
          entity_id: input_select.timer_switch
          option: "选择设备"
  - alias: timer_switch_turnoff
    hide_entity: true
    trigger:
      platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.timer
    condition:
      condition: state
      entity_id: input_select.timer_state
      state: '关'         
    action:
      - service: homeassistant.turn_off
        data_template:
          entity_id: >-
            {% if is_state("input_select.timer_switch", "客厅大灯") %}
              light.fsl002_cloud_646808
            {% elif is_state("input_select.timer_switch", "客厅餐灯") %}
              light.wy0b01_cloud_056917
            {% elif is_state("input_select.timer_switch", "未定义8") %}
              switch.entity_id8
            {% elif is_state("input_select.timer_switch", "未定义9") %}
              switch.entity_id9
            {% elif is_state("input_select.timer_switch", "未定义0") %}
              switch.entity_id0
            {% endif %}
      - service: input_select.select_option
        data:
          entity_id: input_select.timer_switch
          option: "选择设备"



回复

使用道具 举报

15

主题

229

帖子

1520

积分

金牌会员

Rank: 6Rank: 6

积分
1520
金钱
1291
HASS币
0
发表于 2023-5-17 19:39:28 | 显示全部楼层
hunl1986 发表于 2023-5-17 17:52
终于搞定,原来climate.set_operation_mode服务不能用,要改为climate.set_hvac_mode,新版本原来的代码不 ...

你好 还能告诉我一下这个怎么弄的啊
回复

使用道具 举报

15

主题

229

帖子

1520

积分

金牌会员

Rank: 6Rank: 6

积分
1520
金钱
1291
HASS币
0
发表于 2023-5-17 20:09:43 | 显示全部楼层
情非殇 发表于 2023-5-17 15:51
第一步:在configuration.yaml增加packages: !include_dir_named packages【注意缩进】

第二步:在.home ...

Integration error: packages - Integration 'packages' not found.   重启不了   还是这个错误
回复

使用道具 举报

10

主题

145

帖子

1619

积分

论坛技术达人

积分
1619
金钱
1469
HASS币
30
发表于 2023-5-17 22:09:00 | 显示全部楼层
cw4774 发表于 2023-5-17 20:09
Integration error: packages - Integration 'packages' not found.   重启不了   还是这个错误 ...

一、在configuration.yaml中增加
homeassistant:
  packages: !include_dir_named packages


二、在config文件夹建packages文件夹
三、在packages建一个timer.yaml文件
四,上面代码写进timer.yaml
五、重启

回复

使用道具 举报

10

主题

145

帖子

1619

积分

论坛技术达人

积分
1619
金钱
1469
HASS币
30
发表于 2023-5-17 22:10:09 | 显示全部楼层
cw4774 发表于 2023-5-17 20:09
Integration error: packages - Integration 'packages' not found.   重启不了   还是这个错误 ...

你少了homeassistant:这个
回复

使用道具 举报

15

主题

229

帖子

1520

积分

金牌会员

Rank: 6Rank: 6

积分
1520
金钱
1291
HASS币
0
发表于 2023-5-19 00:57:45 | 显示全部楼层
hunl1986 发表于 2023-5-17 22:10
你少了homeassistant:这个

可以了没有报错了重启了    那个UI界面怎么搞出来的啊   
回复

使用道具 举报

15

主题

229

帖子

1520

积分

金牌会员

Rank: 6Rank: 6

积分
1520
金钱
1291
HASS币
0
发表于 2023-5-19 19:49:37 | 显示全部楼层
hunl1986 发表于 2023-5-17 22:09
一、在configuration.yaml中增加

可以了不报错了  那个UI界面怎么弄出来的呀
回复

使用道具 举报

15

主题

229

帖子

1520

积分

金牌会员

Rank: 6Rank: 6

积分
1520
金钱
1291
HASS币
0
发表于 2023-5-20 01:49:12 | 显示全部楼层
可以了  谢谢你们了
回复

使用道具 举报

5

主题

61

帖子

842

积分

高级会员

Rank: 4

积分
842
金钱
781
HASS币
0
发表于 2023-6-23 15:48:19 | 显示全部楼层
学习倒计时
回复

使用道具 举报

0

主题

21

帖子

151

积分

注册会员

Rank: 2

积分
151
金钱
130
HASS币
0
发表于 2023-7-4 00:16:58 | 显示全部楼层
刚好需要
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-23 19:47 , Processed in 0.976726 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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