diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 7b64f5dab2f..6175646778f 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -50,6 +50,7 @@ CONF_ACTION = "action" CONF_TRIGGER = "trigger" CONF_CONDITION_TYPE = "condition_type" CONF_INITIAL_STATE = "initial_state" +CONF_SKIP_CONDITION = "skip_condition" CONDITION_USE_TRIGGER_VALUES = "use_trigger_values" CONDITION_TYPE_AND = "and" @@ -107,7 +108,10 @@ PLATFORM_SCHEMA = vol.Schema( ) TRIGGER_SERVICE_SCHEMA = make_entity_service_schema( - {vol.Optional(ATTR_VARIABLES, default={}): dict} + { + vol.Optional(ATTR_VARIABLES, default={}): dict, + vol.Optional(CONF_SKIP_CONDITION, default=True): bool, + } ) RELOAD_SERVICE_SCHEMA = vol.Schema({}) @@ -135,8 +139,8 @@ async def async_setup(hass, config): for entity in await component.async_extract_from_service(service_call): tasks.append( entity.async_trigger( - service_call.data.get(ATTR_VARIABLES), - skip_condition=True, + service_call.data[ATTR_VARIABLES], + skip_condition=service_call.data[CONF_SKIP_CONDITION], context=service_call.context, ) ) diff --git a/homeassistant/components/automation/services.yaml b/homeassistant/components/automation/services.yaml index 90f66036706..ce54220aff4 100644 --- a/homeassistant/components/automation/services.yaml +++ b/homeassistant/components/automation/services.yaml @@ -27,6 +27,9 @@ trigger: entity_id: description: Name of the automation to trigger. example: 'automation.notify_home' + skip_condition: + description: Whether or not the condition will be skipped (defaults to True). + example: True reload: description: Reload the automation configuration. diff --git a/tests/components/automation/common.py b/tests/components/automation/common.py index 95b156bcb14..26521f76d31 100644 --- a/tests/components/automation/common.py +++ b/tests/components/automation/common.py @@ -3,7 +3,11 @@ All containing methods are legacy helpers that should not be used by new components. Instead call the service directly. """ -from homeassistant.components.automation import DOMAIN, SERVICE_TRIGGER +from homeassistant.components.automation import ( + CONF_SKIP_CONDITION, + DOMAIN, + SERVICE_TRIGGER, +) from homeassistant.const import ( ATTR_ENTITY_ID, ENTITY_MATCH_ALL, @@ -37,9 +41,10 @@ async def async_toggle(hass, entity_id=ENTITY_MATCH_ALL): @bind_hass -async def async_trigger(hass, entity_id=ENTITY_MATCH_ALL): +async def async_trigger(hass, entity_id=ENTITY_MATCH_ALL, skip_condition=True): """Trigger specified automation or all.""" data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} + data[CONF_SKIP_CONDITION] = skip_condition await hass.services.async_call(DOMAIN, SERVICE_TRIGGER, data) diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 100dd983243..b0196fdfe60 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -225,6 +225,22 @@ async def test_trigger_service_ignoring_condition(hass, calls): ) assert len(calls) == 1 + await hass.services.async_call( + "automation", + "trigger", + {"entity_id": "automation.test", "skip_condition": True}, + blocking=True, + ) + assert len(calls) == 2 + + await hass.services.async_call( + "automation", + "trigger", + {"entity_id": "automation.test", "skip_condition": False}, + blocking=True, + ) + assert len(calls) == 2 + async def test_two_conditions_with_and(hass, calls): """Test two and conditions."""