本帖最后由 heize 于 2019-8-1 16:44 编辑
不知道还有没有更好的实现方法,刚开始研究ha。。把代码放上来大家讨论:
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
|