mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Add MQTT publish JSON action and subscribe JSON trigger (#193)
* Add MQTT publish JSON action and subscribe JSON trigger * Lint
This commit is contained in:
		| @@ -73,6 +73,24 @@ mqtt: | ||||
|       then: | ||||
|       - deep_sleep.enter: | ||||
|           id: deep_sleep_1 | ||||
|   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; | ||||
|  | ||||
| i2c: | ||||
|   sda: 21 | ||||
| @@ -599,6 +617,7 @@ light: | ||||
|               state = 0; | ||||
|   - platform: rgb | ||||
|     name: "Living Room Lights" | ||||
|     id: living_room_lights | ||||
|     red: pca_0 | ||||
|     green: pca_1 | ||||
|     blue: pca_2 | ||||
|   | ||||
| @@ -76,7 +76,14 @@ sensor: | ||||
|   - platform: mqtt_subscribe | ||||
|     name: "MQTT Subscribe Sensor 1" | ||||
|     topic: "mqtt/topic" | ||||
|     id: the_sensor | ||||
|     qos: 2 | ||||
|     on_value: | ||||
|     - mqtt.publish_json: | ||||
|         topic: the/topic | ||||
|         payload: |- | ||||
|           root["key"] = id(the_sensor).value; | ||||
|           root["greeting"] = "Hello World"; | ||||
|   - platform: cse7766 | ||||
|     voltage: | ||||
|       name: "CSE7766 Voltage" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user