1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Add WiFi/MQTT/API connected condition (#465)

* Add WiFi/MQTT/API connected condition

* Add tests

* Fix namespace
This commit is contained in:
Otto Winter
2019-03-03 16:45:56 +01:00
committed by GitHub
parent 8495ce96a3
commit 4b017e2096
6 changed files with 69 additions and 29 deletions

View File

@@ -78,21 +78,26 @@ mqtt:
on_json_message:
topic: the/topic
then:
- lambda: |-
int data = x["my_data"];
ESP_LOGD("main", "The data is: %d", data);
- light.turn_on:
id: living_room_lights
transition_length: !lambda |-
int length = 1000;
if (x.containsKey("length"))
length = x["length"];
return length;
effect: !lambda |-
const char *effect = "None";
if (x.containsKey("effect"))
effect = x["effect"];
return effect;
- if:
condition:
- wifi.connected:
- mqtt.connected:
then:
- lambda: |-
int data = x["my_data"];
ESP_LOGD("main", "The data is: %d", data);
- light.turn_on:
id: living_room_lights
transition_length: !lambda |-
int length = 1000;
if (x.containsKey("length"))
length = x["length"];
return length;
effect: !lambda |-
const char *effect = "None";
if (x.containsKey("effect"))
effect = x["effect"];
return effect;
i2c:
sda: 21

View File

@@ -185,8 +185,12 @@ text_sensor:
icon: mdi:icon
id: version_sensor
on_value:
- lambda: !lambda |-
ESP_LOGD("main", "The state is %s=%s", x.c_str(), id(version_sensor).state.c_str());
- if:
condition:
- api.connected:
then:
- lambda: !lambda |-
ESP_LOGD("main", "The state is %s=%s", x.c_str(), id(version_sensor).state.c_str());
- script.execute: my_script
- homeassistant.service:
service: notify.html5