Skip to content

Instantly share code, notes, and snippets.

@thomasloven
Created June 17, 2020 13:09
Show Gist options
  • Save thomasloven/654ae5a4d16a75e3b0ad2d7aa8082243 to your computer and use it in GitHub Desktop.
Save thomasloven/654ae5a4d16a75e3b0ad2d7aa8082243 to your computer and use it in GitHub Desktop.
homeassistant:
customize:
package.node_anchors:
coffee_switch: &cfe_switch switch.kaffebryggare
coffee_remote: &cfe_remote switch.kaffekontroll
common: &common
package: 'devices/coffeemaker'
input_boolean.cfe_on:
# Turn on at set time
<<: *common
friendly_name: Morgonkaffe
input_datetime.cfe_on:
<<: *common
# Time at which to start coffeemaker
friendly_name: Tid
input_boolean.cfe_off:
# Turn off automatically
<<: *common
friendly_name: Slå av automatiskt
input_number.cfe_off:
# Minutes until automatic turn-off
<<: *common
friendly_name: Tid (min)
group.coffeemaker_settings:
<<: *common
friendly_name: Coffeemaker
icon: mdi:settings
script.cfe_off:
<<: *common
automation.coffee__timer_on:
<<: *common
automation.coffee__remote_on:
<<: *common
automation.coffee__timer_remote:
<<: *common
automation.coffee__auto_off:
<<: *common
sensor.coffee_runtime:
<<: *common
device: *cfe_switch
input_datetime:
cfe_on:
has_date: false
has_time: true
initial: "06:00"
input_number:
cfe_off:
initial: 20
min: 5
max: 60
step: 5
input_boolean:
cfe_on:
initial: off
cfe_off:
initial: on
sensor:
- platform: template
sensors:
coffee_runtime:
unit_of_measurement: 'min'
entity_id: sensor.ten_sec_force
value_template: >-
{% set device = state_attr('sensor.coffee_runtime', 'device').split('.') %}
{% if is_state('.'.join(device), 'on') %}
{{ ((as_timestamp(now()) - as_timestamp(states[device[0]][device[1]].last_updated))/60)|round(1) }}
{% else %}
0
{% endif %}
- platform: command_line
command: date
name: ten_sec_force
scan_interval: 10
group:
coffeemaker_settings:
control: hidden
entities:
- input_boolean.cfe_on
- input_datetime.cfe_on
- input_boolean.cfe_off
- input_number.cfe_off
script:
cfe_off:
sequence:
- delay: 00:{{ states('input_number.cfe_off') | int}}:00
- service: homeassistant.turn_off
data:
entity_id: *cfe_switch
automation:
- alias: Coffee - Timer On
trigger:
- platform: template
value_template: >
{{ states('sensor.time') == states('input_datetime.cfe_on')[:5] }}
condition:
condition: state
entity_id: input_boolean.cfe_on
state: 'on'
action:
- service: homeassistant.turn_off
data:
entity_id: input_boolean.cfe_on
- service: homeassistant.turn_on
data:
entity_id: *cfe_switch
- alias: Coffee - Remote On
trigger:
- platform: event
event_type: button_pressed
event_data:
entity_id": *cfe_remote
state: "on"
action:
- delay:
milliseconds: 500
- service: homeassistant.toggle
data:
entity_id: *cfe_switch
- alias: Coffee - Auto off
trigger:
platform: state
entity_id: *cfe_switch
to: 'on'
condition:
condition: state
entity_id: input_boolean.cfe_off
state: 'on'
action:
- service: script.cfe_off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment