1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 03:12:20 +01:00

Add template publish actions and switch triggers (#391)

* Add template publish actions and switch triggers

* Fix

* Add tests

* Add cover

* Lint

* Fix

* Fix
This commit is contained in:
Otto Winter
2019-02-10 23:35:07 +01:00
committed by GitHub
parent 61762bf299
commit 4b7a41922c
9 changed files with 165 additions and 17 deletions

View File

@@ -433,13 +433,21 @@ sensor:
update_interval: 15s
- platform: template
name: "Template Sensor"
lambda: >-
id: template_sensor
lambda: |-
if (id(ultrasonic_sensor1).state > 1) {
return 42.0;
} else {
return {};
}
update_interval: 15s
on_value:
- sensor.template.publish:
id: template_sensor
state: 43.0
- sensor.template.publish:
id: template_sensor
state: !lambda 'return NAN;'
- platform: tsl2561
name: "TSL2561 Ambient Light"
address: 0x39
@@ -560,7 +568,8 @@ binary_sensor:
name: "Nextion Component 2 Touch"
- platform: template
name: "Garage Door Open"
lambda: >-
id: garage_door
lambda: |-
if (isnan(id(my_sensor).state)) {
// isnan checks if the ultrasonic sensor echo
// has timed out, resulting in a NaN (not a number) state
@@ -573,6 +582,10 @@ binary_sensor:
// Garage Door is closed.
return false;
}
on_press:
- binary_sensor.template.publish:
id: garage_door
state: OFF
- platform: pn532
uid: 74-10-37-94
name: "PN532 NFC Tag"
@@ -885,6 +898,7 @@ switch:
- -1000
- platform: template
name: Living Room Lights
id: livingroom_lights
optimistic: True
assumed_state: yes
turn_on_action:
@@ -898,6 +912,10 @@ switch:
turn_off_action:
- switch.turn_on: living_room_lights_off
restore_state: False
on_turn_on:
- switch.template.publish:
id: livingroom_lights
state: yes
- platform: restart
name: "Living Room Restart"
- platform: shutdown
@@ -926,6 +944,10 @@ switch:
optimistic: true
assumed_state: no
restore_state: True
on_turn_off:
- switch.template.publish:
id: my_switch
state: !lambda 'return false;'
- platform: uart
name: "UART String Output"
data: 'DataToSend'
@@ -1041,13 +1063,18 @@ time:
cover:
- platform: template
name: "Template Cover"
lambda: >-
id: template_cover
lambda: |-
if (id(binary_sensor1).state) {
return cover::COVER_OPEN;
} else {
return {};
}
optimistic: true
open_action:
- cover.template.publish:
id: template_cover
state: CLOSED
assumed_state: no
debug: