mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	split api and template to get rid of !remove to make groupable
This commit is contained in:
		
							
								
								
									
										89
									
								
								tests/components/api/common-base.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								tests/components/api/common-base.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,89 @@ | |||||||
|  | esphome: | ||||||
|  |   on_boot: | ||||||
|  |     then: | ||||||
|  |       - homeassistant.event: | ||||||
|  |           event: esphome.button_pressed | ||||||
|  |           data: | ||||||
|  |             message: Button was pressed | ||||||
|  |       - homeassistant.action: | ||||||
|  |           action: notify.html5 | ||||||
|  |           data: | ||||||
|  |             message: Button was pressed | ||||||
|  |       - homeassistant.tag_scanned: pulse | ||||||
|  |       - homeassistant.action: | ||||||
|  |           action: weather.get_forecasts | ||||||
|  |           data: | ||||||
|  |             entity_id: weather.forecast_home | ||||||
|  |             type: hourly | ||||||
|  |           capture_response: true | ||||||
|  |           on_success: | ||||||
|  |             - lambda: |- | ||||||
|  |                 JsonObjectConst next_hour = response["response"]["weather.forecast_home"]["forecast"][0]; | ||||||
|  |                 float next_temperature = next_hour["temperature"].as<float>(); | ||||||
|  |                 ESP_LOGD("main", "Next hour temperature: %f", next_temperature); | ||||||
|  |           on_error: | ||||||
|  |             - lambda: |- | ||||||
|  |                 ESP_LOGE("main", "Action failed with error: %s", error.c_str()); | ||||||
|  |       - homeassistant.action: | ||||||
|  |           action: weather.get_forecasts | ||||||
|  |           data: | ||||||
|  |             entity_id: weather.forecast_home | ||||||
|  |             type: hourly | ||||||
|  |           capture_response: true | ||||||
|  |           response_template: "{{ response['weather.forecast_home']['forecast'][0]['temperature'] }}" | ||||||
|  |           on_success: | ||||||
|  |             - lambda: |- | ||||||
|  |                 float temperature = response["response"].as<float>(); | ||||||
|  |                 ESP_LOGD("main", "Next hour temperature: %f", temperature); | ||||||
|  |       - homeassistant.action: | ||||||
|  |           action: light.toggle | ||||||
|  |           data: | ||||||
|  |             entity_id: light.demo_light | ||||||
|  |           on_success: | ||||||
|  |             - logger.log: "Toggled demo light" | ||||||
|  |           on_error: | ||||||
|  |             - logger.log: "Failed to toggle demo light" | ||||||
|  |  | ||||||
|  | api: | ||||||
|  |   port: 8000 | ||||||
|  |   reboot_timeout: 0min | ||||||
|  |   actions: | ||||||
|  |     - action: hello_world | ||||||
|  |       variables: | ||||||
|  |         name: string | ||||||
|  |       then: | ||||||
|  |         - logger.log: | ||||||
|  |             format: Hello World %s! | ||||||
|  |             args: | ||||||
|  |               - name.c_str() | ||||||
|  |     - action: empty_action | ||||||
|  |       then: | ||||||
|  |         - logger.log: Action Called | ||||||
|  |     - action: all_types | ||||||
|  |       variables: | ||||||
|  |         bool_: bool | ||||||
|  |         int_: int | ||||||
|  |         float_: float | ||||||
|  |         string_: string | ||||||
|  |       then: | ||||||
|  |         - logger.log: Something happened | ||||||
|  |     - action: array_types | ||||||
|  |       variables: | ||||||
|  |         bool_arr: bool[] | ||||||
|  |         int_arr: int[] | ||||||
|  |         float_arr: float[] | ||||||
|  |         string_arr: string[] | ||||||
|  |       then: | ||||||
|  |         - logger.log: | ||||||
|  |             # yamllint disable rule:line-length | ||||||
|  |             format: "Bool: %s (%u), Int: %ld (%u), Float: %f (%u), String: %s (%u)" | ||||||
|  |             # yamllint enable rule:line-length | ||||||
|  |             args: | ||||||
|  |               - YESNO(bool_arr[0]) | ||||||
|  |               - bool_arr.size() | ||||||
|  |               - (long) int_arr[0] | ||||||
|  |               - int_arr.size() | ||||||
|  |               - float_arr[0] | ||||||
|  |               - float_arr.size() | ||||||
|  |               - string_arr[0].c_str() | ||||||
|  |               - string_arr.size() | ||||||
| @@ -1,91 +1,5 @@ | |||||||
| esphome: | <<: !include common-base.yaml | ||||||
|   on_boot: |  | ||||||
|     then: |  | ||||||
|       - homeassistant.event: |  | ||||||
|           event: esphome.button_pressed |  | ||||||
|           data: |  | ||||||
|             message: Button was pressed |  | ||||||
|       - homeassistant.action: |  | ||||||
|           action: notify.html5 |  | ||||||
|           data: |  | ||||||
|             message: Button was pressed |  | ||||||
|       - homeassistant.tag_scanned: pulse |  | ||||||
|       - homeassistant.action: |  | ||||||
|           action: weather.get_forecasts |  | ||||||
|           data: |  | ||||||
|             entity_id: weather.forecast_home |  | ||||||
|             type: hourly |  | ||||||
|           capture_response: true |  | ||||||
|           on_success: |  | ||||||
|             - lambda: |- |  | ||||||
|                 JsonObjectConst next_hour = response["response"]["weather.forecast_home"]["forecast"][0]; |  | ||||||
|                 float next_temperature = next_hour["temperature"].as<float>(); |  | ||||||
|                 ESP_LOGD("main", "Next hour temperature: %f", next_temperature); |  | ||||||
|           on_error: |  | ||||||
|             - lambda: |- |  | ||||||
|                 ESP_LOGE("main", "Action failed with error: %s", error.c_str()); |  | ||||||
|       - homeassistant.action: |  | ||||||
|           action: weather.get_forecasts |  | ||||||
|           data: |  | ||||||
|             entity_id: weather.forecast_home |  | ||||||
|             type: hourly |  | ||||||
|           capture_response: true |  | ||||||
|           response_template: "{{ response['weather.forecast_home']['forecast'][0]['temperature'] }}" |  | ||||||
|           on_success: |  | ||||||
|             - lambda: |- |  | ||||||
|                 float temperature = response["response"].as<float>(); |  | ||||||
|                 ESP_LOGD("main", "Next hour temperature: %f", temperature); |  | ||||||
|       - homeassistant.action: |  | ||||||
|           action: light.toggle |  | ||||||
|           data: |  | ||||||
|             entity_id: light.demo_light |  | ||||||
|           on_success: |  | ||||||
|             - logger.log: "Toggled demo light" |  | ||||||
|           on_error: |  | ||||||
|             - logger.log: "Failed to toggle demo light" |  | ||||||
|  |  | ||||||
| api: | api: | ||||||
|   port: 8000 |  | ||||||
|   reboot_timeout: 0min |  | ||||||
|   encryption: |   encryption: | ||||||
|     key: bOFFzzvfpg5DB94DuBGLXD/hMnhpDKgP9UQyBulwWVU= |     key: bOFFzzvfpg5DB94DuBGLXD/hMnhpDKgP9UQyBulwWVU= | ||||||
|   actions: |  | ||||||
|     - action: hello_world |  | ||||||
|       variables: |  | ||||||
|         name: string |  | ||||||
|       then: |  | ||||||
|         - logger.log: |  | ||||||
|             format: Hello World %s! |  | ||||||
|             args: |  | ||||||
|               - name.c_str() |  | ||||||
|     - action: empty_action |  | ||||||
|       then: |  | ||||||
|         - logger.log: Action Called |  | ||||||
|     - action: all_types |  | ||||||
|       variables: |  | ||||||
|         bool_: bool |  | ||||||
|         int_: int |  | ||||||
|         float_: float |  | ||||||
|         string_: string |  | ||||||
|       then: |  | ||||||
|         - logger.log: Something happened |  | ||||||
|     - action: array_types |  | ||||||
|       variables: |  | ||||||
|         bool_arr: bool[] |  | ||||||
|         int_arr: int[] |  | ||||||
|         float_arr: float[] |  | ||||||
|         string_arr: string[] |  | ||||||
|       then: |  | ||||||
|         - logger.log: |  | ||||||
|             # yamllint disable rule:line-length |  | ||||||
|             format: "Bool: %s (%u), Int: %ld (%u), Float: %f (%u), String: %s (%u)" |  | ||||||
|             # yamllint enable rule:line-length |  | ||||||
|             args: |  | ||||||
|               - YESNO(bool_arr[0]) |  | ||||||
|               - bool_arr.size() |  | ||||||
|               - (long) int_arr[0] |  | ||||||
|               - int_arr.size() |  | ||||||
|               - float_arr[0] |  | ||||||
|               - float_arr.size() |  | ||||||
|               - string_arr[0].c_str() |  | ||||||
|               - string_arr.size() |  | ||||||
|   | |||||||
| @@ -1,10 +1,5 @@ | |||||||
| packages: | <<: !include common-base.yaml | ||||||
|   common: !include common.yaml |  | ||||||
|  |  | ||||||
| wifi: | wifi: | ||||||
|   ssid: MySSID |   ssid: MySSID | ||||||
|   password: password1 |   password: password1 | ||||||
|  |  | ||||||
| api: |  | ||||||
|   encryption: |  | ||||||
|     key: !remove |  | ||||||
|   | |||||||
							
								
								
									
										340
									
								
								tests/components/template/common-base.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										340
									
								
								tests/components/template/common-base.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,340 @@ | |||||||
|  | esphome: | ||||||
|  |   on_boot: | ||||||
|  |     - sensor.template.publish: | ||||||
|  |         id: template_sens | ||||||
|  |         state: 42.0 | ||||||
|  |  | ||||||
|  |     # Templated | ||||||
|  |     - sensor.template.publish: | ||||||
|  |         id: template_sens | ||||||
|  |         state: !lambda "return 42.0;" | ||||||
|  |  | ||||||
|  |     - datetime.date.set: | ||||||
|  |         id: test_date | ||||||
|  |         date: | ||||||
|  |           year: 2021 | ||||||
|  |           month: 1 | ||||||
|  |           day: 1 | ||||||
|  |     - datetime.date.set: | ||||||
|  |         id: test_date | ||||||
|  |         date: !lambda "return {.day_of_month = 1, .month = 1, .year = 2021};" | ||||||
|  |     - datetime.date.set: | ||||||
|  |         id: test_date | ||||||
|  |         date: "2021-01-01" | ||||||
|  |  | ||||||
|  | binary_sensor: | ||||||
|  |   - platform: template | ||||||
|  |     id: some_binary_sensor | ||||||
|  |     name: "Garage Door Open" | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(template_sens).state > 30) { | ||||||
|  |         // Garage Door is open. | ||||||
|  |         return true; | ||||||
|  |       } else { | ||||||
|  |         // Garage Door is closed. | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |   - platform: template | ||||||
|  |     id: other_binary_sensor | ||||||
|  |     name: "Garage Door Closed" | ||||||
|  |     condition: | ||||||
|  |       sensor.in_range: | ||||||
|  |         id: template_sens | ||||||
|  |         below: 30.0 | ||||||
|  |     filters: | ||||||
|  |       - invert: | ||||||
|  |       - delayed_on: 100ms | ||||||
|  |       - delayed_off: 100ms | ||||||
|  |       - delayed_on_off: !lambda "if (id(test_switch).state) return 1000; else return 0;" | ||||||
|  |       - delayed_on_off: | ||||||
|  |           time_on: 10s | ||||||
|  |           time_off: !lambda "if (id(test_switch).state) return 1000; else return 0;" | ||||||
|  |       - autorepeat: | ||||||
|  |           - delay: 1s | ||||||
|  |             time_off: 100ms | ||||||
|  |             time_on: 900ms | ||||||
|  |           - delay: 5s | ||||||
|  |             time_off: 100ms | ||||||
|  |             time_on: 400ms | ||||||
|  |       - lambda: |- | ||||||
|  |           if (id(other_binary_sensor).state) { | ||||||
|  |             return x; | ||||||
|  |           } else { | ||||||
|  |             return {}; | ||||||
|  |           } | ||||||
|  |       - settle: 500ms | ||||||
|  |       - timeout: 5s | ||||||
|  |  | ||||||
|  | sensor: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template Sensor" | ||||||
|  |     id: template_sens | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(some_binary_sensor).state) { | ||||||
|  |         return 42.0; | ||||||
|  |       } else { | ||||||
|  |         return 0.0; | ||||||
|  |       } | ||||||
|  |     update_interval: 60s | ||||||
|  |     filters: | ||||||
|  |       - calibrate_linear: | ||||||
|  |           - 0.0 -> 0.0 | ||||||
|  |           - 40.0 -> 45.0 | ||||||
|  |           - 100.0 -> 102.5 | ||||||
|  |       - calibrate_polynomial: | ||||||
|  |           degree: 2 | ||||||
|  |           datapoints: | ||||||
|  |             # Map 0.0 (from sensor) to 0.0 (true value) | ||||||
|  |             - 0.0 -> 0.0 | ||||||
|  |             - 10.0 -> 12.1 | ||||||
|  |             - 13.0 -> 14.0 | ||||||
|  |       - clamp: | ||||||
|  |           max_value: 10.0 | ||||||
|  |           min_value: -10.0 | ||||||
|  |       - debounce: 0.1s | ||||||
|  |       - delta: 5.0 | ||||||
|  |       - exponential_moving_average: | ||||||
|  |           alpha: 0.1 | ||||||
|  |           send_every: 15 | ||||||
|  |       - filter_out: | ||||||
|  |           - 10 | ||||||
|  |           - 20 | ||||||
|  |           - !lambda return 10; | ||||||
|  |       - filter_out: 10 | ||||||
|  |       - filter_out: !lambda return NAN; | ||||||
|  |       - heartbeat: 5s | ||||||
|  |       - lambda: return x * (9.0/5.0) + 32.0; | ||||||
|  |       - max: | ||||||
|  |           window_size: 10 | ||||||
|  |           send_every: 2 | ||||||
|  |           send_first_at: 1 | ||||||
|  |       - median: | ||||||
|  |           window_size: 7 | ||||||
|  |           send_every: 4 | ||||||
|  |           send_first_at: 3 | ||||||
|  |       - min: | ||||||
|  |           window_size: 10 | ||||||
|  |           send_every: 2 | ||||||
|  |           send_first_at: 1 | ||||||
|  |       - multiply: 1 | ||||||
|  |       - multiply: !lambda return 2; | ||||||
|  |       - offset: 10 | ||||||
|  |       - offset: !lambda return 10; | ||||||
|  |       - or: | ||||||
|  |           - quantile: | ||||||
|  |               window_size: 7 | ||||||
|  |               send_every: 4 | ||||||
|  |               send_first_at: 3 | ||||||
|  |               quantile: .9 | ||||||
|  |           - round: 1 | ||||||
|  |       - round_to_multiple_of: 0.25 | ||||||
|  |       - skip_initial: 3 | ||||||
|  |       - sliding_window_moving_average: | ||||||
|  |           window_size: 15 | ||||||
|  |           send_every: 15 | ||||||
|  |       - throttle: 1s | ||||||
|  |       - throttle_average: 2s | ||||||
|  |       - throttle_with_priority: 5s | ||||||
|  |       - throttle_with_priority: | ||||||
|  |           timeout: 3s | ||||||
|  |           value: 42.0 | ||||||
|  |       - throttle_with_priority: | ||||||
|  |           timeout: 3s | ||||||
|  |           value: !lambda return 1.0f / 2.0f; | ||||||
|  |       - throttle_with_priority: | ||||||
|  |           timeout: 3s | ||||||
|  |           value: | ||||||
|  |             - 42.0 | ||||||
|  |             - !lambda return 2.0f / 2.0f; | ||||||
|  |             - nan | ||||||
|  |       - timeout: | ||||||
|  |           timeout: 10s | ||||||
|  |           value: !lambda return 10; | ||||||
|  |       - timeout: | ||||||
|  |           timeout: 1h | ||||||
|  |           value: 20.0 | ||||||
|  |       - timeout: | ||||||
|  |           timeout: 1min | ||||||
|  |           value: last | ||||||
|  |       - timeout: | ||||||
|  |           timeout: 1d | ||||||
|  |       - to_ntc_resistance: | ||||||
|  |           calibration: | ||||||
|  |             - 10.0kOhm -> 25°C | ||||||
|  |             - 27.219kOhm -> 0°C | ||||||
|  |             - 14.674kOhm -> 15°C | ||||||
|  |       - to_ntc_temperature: | ||||||
|  |           calibration: | ||||||
|  |             - 10.0kOhm -> 25°C | ||||||
|  |             - 27.219kOhm -> 0°C | ||||||
|  |             - 14.674kOhm -> 15°C | ||||||
|  |  | ||||||
|  | output: | ||||||
|  |   - platform: template | ||||||
|  |     id: outputsplit | ||||||
|  |     type: float | ||||||
|  |     write_action: | ||||||
|  |       - logger.log: "write_action" | ||||||
|  |  | ||||||
|  | switch: | ||||||
|  |   - platform: template | ||||||
|  |     id: test_switch | ||||||
|  |     name: "Template Switch" | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(some_binary_sensor).state) { | ||||||
|  |         return true; | ||||||
|  |       } else { | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |     turn_on_action: | ||||||
|  |       - logger.log: "turn_on_action" | ||||||
|  |     turn_off_action: | ||||||
|  |       - logger.log: "turn_off_action" | ||||||
|  |  | ||||||
|  | button: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template Button" | ||||||
|  |     on_press: | ||||||
|  |       - logger.log: Button Pressed | ||||||
|  |  | ||||||
|  | cover: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template Cover" | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(some_binary_sensor).state) { | ||||||
|  |         return COVER_OPEN; | ||||||
|  |       } else { | ||||||
|  |         return COVER_CLOSED; | ||||||
|  |       } | ||||||
|  |     open_action: | ||||||
|  |       - logger.log: open_action | ||||||
|  |     close_action: | ||||||
|  |       - logger.log: close_action | ||||||
|  |     stop_action: | ||||||
|  |       - logger.log: stop_action | ||||||
|  |     optimistic: true | ||||||
|  |  | ||||||
|  | number: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template number" | ||||||
|  |     optimistic: true | ||||||
|  |     min_value: 0 | ||||||
|  |     max_value: 100 | ||||||
|  |     step: 1 | ||||||
|  |  | ||||||
|  | select: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template select" | ||||||
|  |     optimistic: true | ||||||
|  |     options: | ||||||
|  |       - one | ||||||
|  |       - two | ||||||
|  |       - three | ||||||
|  |     initial_option: two | ||||||
|  |  | ||||||
|  | lock: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template Lock" | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(some_binary_sensor).state) { | ||||||
|  |         return LOCK_STATE_LOCKED; | ||||||
|  |       } else { | ||||||
|  |         return LOCK_STATE_UNLOCKED; | ||||||
|  |       } | ||||||
|  |     lock_action: | ||||||
|  |       - logger.log: lock_action | ||||||
|  |     unlock_action: | ||||||
|  |       - logger.log: unlock_action | ||||||
|  |     open_action: | ||||||
|  |       - logger.log: open_action | ||||||
|  |  | ||||||
|  | valve: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template Valve" | ||||||
|  |     lambda: |- | ||||||
|  |       if (id(some_binary_sensor).state) { | ||||||
|  |         return VALVE_OPEN; | ||||||
|  |       } else { | ||||||
|  |         return VALVE_CLOSED; | ||||||
|  |       } | ||||||
|  |     open_action: | ||||||
|  |       - logger.log: open_action | ||||||
|  |     close_action: | ||||||
|  |       - logger.log: close_action | ||||||
|  |       - valve.template.publish: | ||||||
|  |           state: CLOSED | ||||||
|  |     stop_action: | ||||||
|  |       - logger.log: stop_action | ||||||
|  |     optimistic: true | ||||||
|  |  | ||||||
|  | text: | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template text" | ||||||
|  |     optimistic: true | ||||||
|  |     min_length: 0 | ||||||
|  |     max_length: 100 | ||||||
|  |     mode: text | ||||||
|  |   - platform: template | ||||||
|  |     name: "Template text lambda" | ||||||
|  |     mode: text | ||||||
|  |     update_interval: 1s | ||||||
|  |     lambda: | | ||||||
|  |       return std::string{"Hello!"}; | ||||||
|  |     set_action: | ||||||
|  |       then: | ||||||
|  |         - logger.log: | ||||||
|  |             format: Template Text set to %s | ||||||
|  |             args: ["x.c_str()"] | ||||||
|  |  | ||||||
|  | alarm_control_panel: | ||||||
|  |   - platform: template | ||||||
|  |     name: Alarm Panel | ||||||
|  |     codes: | ||||||
|  |       - "1234" | ||||||
|  |  | ||||||
|  | datetime: | ||||||
|  |   - platform: template | ||||||
|  |     name: Date | ||||||
|  |     id: test_date | ||||||
|  |     type: date | ||||||
|  |     initial_value: "2000-1-2" | ||||||
|  |     set_action: | ||||||
|  |       - logger.log: "set_value" | ||||||
|  |     on_value: | ||||||
|  |       - logger.log: | ||||||
|  |           format: "Date: %04d-%02d-%02d" | ||||||
|  |           args: | ||||||
|  |             - x.year | ||||||
|  |             - x.month | ||||||
|  |             - x.day_of_month | ||||||
|  |   - platform: template | ||||||
|  |     name: Time | ||||||
|  |     id: test_time | ||||||
|  |     type: time | ||||||
|  |     initial_value: "12:34:56am" | ||||||
|  |     set_action: | ||||||
|  |       - logger.log: "set_value" | ||||||
|  |     on_value: | ||||||
|  |       - logger.log: | ||||||
|  |           format: "Time: %02d:%02d:%02d" | ||||||
|  |           args: | ||||||
|  |             - x.hour | ||||||
|  |             - x.minute | ||||||
|  |             - x.second | ||||||
|  |   - platform: template | ||||||
|  |     name: DateTime | ||||||
|  |     id: test_datetime | ||||||
|  |     type: datetime | ||||||
|  |     initial_value: "2000-1-2 12:34:56" | ||||||
|  |     set_action: | ||||||
|  |       - logger.log: "set_value" | ||||||
|  |     on_value: | ||||||
|  |       - logger.log: | ||||||
|  |           format: "DateTime: %04d-%02d-%02d %02d:%02d:%02d" | ||||||
|  |           args: | ||||||
|  |             - x.year | ||||||
|  |             - x.month | ||||||
|  |             - x.day_of_month | ||||||
|  |             - x.hour | ||||||
|  |             - x.minute | ||||||
|  |             - x.second | ||||||
| @@ -1,343 +1,4 @@ | |||||||
| esphome: | <<: !include common-base.yaml | ||||||
|   on_boot: |  | ||||||
|     - sensor.template.publish: |  | ||||||
|         id: template_sens |  | ||||||
|         state: 42.0 |  | ||||||
|  |  | ||||||
|     # Templated |  | ||||||
|     - sensor.template.publish: |  | ||||||
|         id: template_sens |  | ||||||
|         state: !lambda "return 42.0;" |  | ||||||
|  |  | ||||||
|     - datetime.date.set: |  | ||||||
|         id: test_date |  | ||||||
|         date: |  | ||||||
|           year: 2021 |  | ||||||
|           month: 1 |  | ||||||
|           day: 1 |  | ||||||
|     - datetime.date.set: |  | ||||||
|         id: test_date |  | ||||||
|         date: !lambda "return {.day_of_month = 1, .month = 1, .year = 2021};" |  | ||||||
|     - datetime.date.set: |  | ||||||
|         id: test_date |  | ||||||
|         date: "2021-01-01" |  | ||||||
|  |  | ||||||
| binary_sensor: |  | ||||||
|   - platform: template |  | ||||||
|     id: some_binary_sensor |  | ||||||
|     name: "Garage Door Open" |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(template_sens).state > 30) { |  | ||||||
|         // Garage Door is open. |  | ||||||
|         return true; |  | ||||||
|       } else { |  | ||||||
|         // Garage Door is closed. |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|   - platform: template |  | ||||||
|     id: other_binary_sensor |  | ||||||
|     name: "Garage Door Closed" |  | ||||||
|     condition: |  | ||||||
|       sensor.in_range: |  | ||||||
|         id: template_sens |  | ||||||
|         below: 30.0 |  | ||||||
|     filters: |  | ||||||
|       - invert: |  | ||||||
|       - delayed_on: 100ms |  | ||||||
|       - delayed_off: 100ms |  | ||||||
|       - delayed_on_off: !lambda "if (id(test_switch).state) return 1000; else return 0;" |  | ||||||
|       - delayed_on_off: |  | ||||||
|           time_on: 10s |  | ||||||
|           time_off: !lambda "if (id(test_switch).state) return 1000; else return 0;" |  | ||||||
|       - autorepeat: |  | ||||||
|           - delay: 1s |  | ||||||
|             time_off: 100ms |  | ||||||
|             time_on: 900ms |  | ||||||
|           - delay: 5s |  | ||||||
|             time_off: 100ms |  | ||||||
|             time_on: 400ms |  | ||||||
|       - lambda: |- |  | ||||||
|           if (id(other_binary_sensor).state) { |  | ||||||
|             return x; |  | ||||||
|           } else { |  | ||||||
|             return {}; |  | ||||||
|           } |  | ||||||
|       - settle: 500ms |  | ||||||
|       - timeout: 5s |  | ||||||
|  |  | ||||||
| sensor: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template Sensor" |  | ||||||
|     id: template_sens |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(some_binary_sensor).state) { |  | ||||||
|         return 42.0; |  | ||||||
|       } else { |  | ||||||
|         return 0.0; |  | ||||||
|       } |  | ||||||
|     update_interval: 60s |  | ||||||
|     filters: |  | ||||||
|       - calibrate_linear: |  | ||||||
|           - 0.0 -> 0.0 |  | ||||||
|           - 40.0 -> 45.0 |  | ||||||
|           - 100.0 -> 102.5 |  | ||||||
|       - calibrate_polynomial: |  | ||||||
|           degree: 2 |  | ||||||
|           datapoints: |  | ||||||
|             # Map 0.0 (from sensor) to 0.0 (true value) |  | ||||||
|             - 0.0 -> 0.0 |  | ||||||
|             - 10.0 -> 12.1 |  | ||||||
|             - 13.0 -> 14.0 |  | ||||||
|       - clamp: |  | ||||||
|           max_value: 10.0 |  | ||||||
|           min_value: -10.0 |  | ||||||
|       - debounce: 0.1s |  | ||||||
|       - delta: 5.0 |  | ||||||
|       - exponential_moving_average: |  | ||||||
|           alpha: 0.1 |  | ||||||
|           send_every: 15 |  | ||||||
|       - filter_out: |  | ||||||
|           - 10 |  | ||||||
|           - 20 |  | ||||||
|           - !lambda return 10; |  | ||||||
|       - filter_out: 10 |  | ||||||
|       - filter_out: !lambda return NAN; |  | ||||||
|       - heartbeat: 5s |  | ||||||
|       - lambda: return x * (9.0/5.0) + 32.0; |  | ||||||
|       - max: |  | ||||||
|           window_size: 10 |  | ||||||
|           send_every: 2 |  | ||||||
|           send_first_at: 1 |  | ||||||
|       - median: |  | ||||||
|           window_size: 7 |  | ||||||
|           send_every: 4 |  | ||||||
|           send_first_at: 3 |  | ||||||
|       - min: |  | ||||||
|           window_size: 10 |  | ||||||
|           send_every: 2 |  | ||||||
|           send_first_at: 1 |  | ||||||
|       - multiply: 1 |  | ||||||
|       - multiply: !lambda return 2; |  | ||||||
|       - offset: 10 |  | ||||||
|       - offset: !lambda return 10; |  | ||||||
|       - or: |  | ||||||
|           - quantile: |  | ||||||
|               window_size: 7 |  | ||||||
|               send_every: 4 |  | ||||||
|               send_first_at: 3 |  | ||||||
|               quantile: .9 |  | ||||||
|           - round: 1 |  | ||||||
|       - round_to_multiple_of: 0.25 |  | ||||||
|       - skip_initial: 3 |  | ||||||
|       - sliding_window_moving_average: |  | ||||||
|           window_size: 15 |  | ||||||
|           send_every: 15 |  | ||||||
|       - throttle: 1s |  | ||||||
|       - throttle_average: 2s |  | ||||||
|       - throttle_with_priority: 5s |  | ||||||
|       - throttle_with_priority: |  | ||||||
|           timeout: 3s |  | ||||||
|           value: 42.0 |  | ||||||
|       - throttle_with_priority: |  | ||||||
|           timeout: 3s |  | ||||||
|           value: !lambda return 1.0f / 2.0f; |  | ||||||
|       - throttle_with_priority: |  | ||||||
|           timeout: 3s |  | ||||||
|           value: |  | ||||||
|             - 42.0 |  | ||||||
|             - !lambda return 2.0f / 2.0f; |  | ||||||
|             - nan |  | ||||||
|       - timeout: |  | ||||||
|           timeout: 10s |  | ||||||
|           value: !lambda return 10; |  | ||||||
|       - timeout: |  | ||||||
|           timeout: 1h |  | ||||||
|           value: 20.0 |  | ||||||
|       - timeout: |  | ||||||
|           timeout: 1min |  | ||||||
|           value: last |  | ||||||
|       - timeout: |  | ||||||
|           timeout: 1d |  | ||||||
|       - to_ntc_resistance: |  | ||||||
|           calibration: |  | ||||||
|             - 10.0kOhm -> 25°C |  | ||||||
|             - 27.219kOhm -> 0°C |  | ||||||
|             - 14.674kOhm -> 15°C |  | ||||||
|       - to_ntc_temperature: |  | ||||||
|           calibration: |  | ||||||
|             - 10.0kOhm -> 25°C |  | ||||||
|             - 27.219kOhm -> 0°C |  | ||||||
|             - 14.674kOhm -> 15°C |  | ||||||
|  |  | ||||||
| output: |  | ||||||
|   - platform: template |  | ||||||
|     id: outputsplit |  | ||||||
|     type: float |  | ||||||
|     write_action: |  | ||||||
|       - logger.log: "write_action" |  | ||||||
|  |  | ||||||
| switch: |  | ||||||
|   - platform: template |  | ||||||
|     id: test_switch |  | ||||||
|     name: "Template Switch" |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(some_binary_sensor).state) { |  | ||||||
|         return true; |  | ||||||
|       } else { |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|     turn_on_action: |  | ||||||
|       - logger.log: "turn_on_action" |  | ||||||
|     turn_off_action: |  | ||||||
|       - logger.log: "turn_off_action" |  | ||||||
|  |  | ||||||
| button: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template Button" |  | ||||||
|     on_press: |  | ||||||
|       - logger.log: Button Pressed |  | ||||||
|  |  | ||||||
| cover: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template Cover" |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(some_binary_sensor).state) { |  | ||||||
|         return COVER_OPEN; |  | ||||||
|       } else { |  | ||||||
|         return COVER_CLOSED; |  | ||||||
|       } |  | ||||||
|     open_action: |  | ||||||
|       - logger.log: open_action |  | ||||||
|     close_action: |  | ||||||
|       - logger.log: close_action |  | ||||||
|     stop_action: |  | ||||||
|       - logger.log: stop_action |  | ||||||
|     optimistic: true |  | ||||||
|  |  | ||||||
| number: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template number" |  | ||||||
|     optimistic: true |  | ||||||
|     min_value: 0 |  | ||||||
|     max_value: 100 |  | ||||||
|     step: 1 |  | ||||||
|  |  | ||||||
| select: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template select" |  | ||||||
|     optimistic: true |  | ||||||
|     options: |  | ||||||
|       - one |  | ||||||
|       - two |  | ||||||
|       - three |  | ||||||
|     initial_option: two |  | ||||||
|  |  | ||||||
| lock: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template Lock" |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(some_binary_sensor).state) { |  | ||||||
|         return LOCK_STATE_LOCKED; |  | ||||||
|       } else { |  | ||||||
|         return LOCK_STATE_UNLOCKED; |  | ||||||
|       } |  | ||||||
|     lock_action: |  | ||||||
|       - logger.log: lock_action |  | ||||||
|     unlock_action: |  | ||||||
|       - logger.log: unlock_action |  | ||||||
|     open_action: |  | ||||||
|       - logger.log: open_action |  | ||||||
|  |  | ||||||
| valve: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template Valve" |  | ||||||
|     lambda: |- |  | ||||||
|       if (id(some_binary_sensor).state) { |  | ||||||
|         return VALVE_OPEN; |  | ||||||
|       } else { |  | ||||||
|         return VALVE_CLOSED; |  | ||||||
|       } |  | ||||||
|     open_action: |  | ||||||
|       - logger.log: open_action |  | ||||||
|     close_action: |  | ||||||
|       - logger.log: close_action |  | ||||||
|       - valve.template.publish: |  | ||||||
|           state: CLOSED |  | ||||||
|     stop_action: |  | ||||||
|       - logger.log: stop_action |  | ||||||
|     optimistic: true |  | ||||||
|  |  | ||||||
| text: |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template text" |  | ||||||
|     optimistic: true |  | ||||||
|     min_length: 0 |  | ||||||
|     max_length: 100 |  | ||||||
|     mode: text |  | ||||||
|   - platform: template |  | ||||||
|     name: "Template text lambda" |  | ||||||
|     mode: text |  | ||||||
|     update_interval: 1s |  | ||||||
|     lambda: | |  | ||||||
|       return std::string{"Hello!"}; |  | ||||||
|     set_action: |  | ||||||
|       then: |  | ||||||
|         - logger.log: |  | ||||||
|             format: Template Text set to %s |  | ||||||
|             args: ["x.c_str()"] |  | ||||||
|  |  | ||||||
| alarm_control_panel: |  | ||||||
|   - platform: template |  | ||||||
|     name: Alarm Panel |  | ||||||
|     codes: |  | ||||||
|       - "1234" |  | ||||||
|  |  | ||||||
| datetime: |  | ||||||
|   - platform: template |  | ||||||
|     name: Date |  | ||||||
|     id: test_date |  | ||||||
|     type: date |  | ||||||
|     initial_value: "2000-1-2" |  | ||||||
|     set_action: |  | ||||||
|       - logger.log: "set_value" |  | ||||||
|     on_value: |  | ||||||
|       - logger.log: |  | ||||||
|           format: "Date: %04d-%02d-%02d" |  | ||||||
|           args: |  | ||||||
|             - x.year |  | ||||||
|             - x.month |  | ||||||
|             - x.day_of_month |  | ||||||
|   - platform: template |  | ||||||
|     name: Time |  | ||||||
|     id: test_time |  | ||||||
|     type: time |  | ||||||
|     initial_value: "12:34:56am" |  | ||||||
|     set_action: |  | ||||||
|       - logger.log: "set_value" |  | ||||||
|     on_value: |  | ||||||
|       - logger.log: |  | ||||||
|           format: "Time: %02d:%02d:%02d" |  | ||||||
|           args: |  | ||||||
|             - x.hour |  | ||||||
|             - x.minute |  | ||||||
|             - x.second |  | ||||||
|   - platform: template |  | ||||||
|     name: DateTime |  | ||||||
|     id: test_datetime |  | ||||||
|     type: datetime |  | ||||||
|     initial_value: "2000-1-2 12:34:56" |  | ||||||
|     set_action: |  | ||||||
|       - logger.log: "set_value" |  | ||||||
|     on_value: |  | ||||||
|       - logger.log: |  | ||||||
|           format: "DateTime: %04d-%02d-%02d %02d:%02d:%02d" |  | ||||||
|           args: |  | ||||||
|             - x.year |  | ||||||
|             - x.month |  | ||||||
|             - x.day_of_month |  | ||||||
|             - x.hour |  | ||||||
|             - x.minute |  | ||||||
|             - x.second |  | ||||||
|  |  | ||||||
| time: | time: | ||||||
|   - platform: sntp  # Required for datetime |   - platform: sntp  # Required for datetime | ||||||
|   | |||||||
| @@ -1,6 +1 @@ | |||||||
| packages: !include common.yaml | <<: !include common-base.yaml | ||||||
|  |  | ||||||
| time: |  | ||||||
|   - id: !remove sntp_time |  | ||||||
|  |  | ||||||
| wifi: !remove |  | ||||||
|   | |||||||
| @@ -1,6 +1 @@ | |||||||
| packages: !include common.yaml | <<: !include common-base.yaml | ||||||
|  |  | ||||||
| time: |  | ||||||
|   - id: !remove sntp_time |  | ||||||
|  |  | ||||||
| wifi: !remove |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user