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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user