New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make variable `entity_id` available to value_template for MQTT binary sensor #19195

merged 3 commits into from Dec 14, 2018


None yet
4 participants
Copy link

emontnemery commented Dec 11, 2018


#18501, which proposed adding "toggle" functionality to binary sensor, was closed because the same thing should already be possible to achieve with a value template.

Doing it with a value template however requires hard coding the entity_id, which is tedious and error prone in case of manual edit of configuration.yaml, and impossible if the entity is automatically discovered.

This PR makes variable entity_id available to the value_template, in the same manner as it is already available to automation templates.

Pull request in with documentation (if applicable): home-assistant/

Example entry for configuration.yaml (if applicable):

# Toggle the binary sensor each time a message is received on state_topic
  - platform: mqtt
    value_template:"{%if is_state(entity_id,\"on\")-%}OFF{%-else-%}ON{%-endif%}"}


  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@fabaff fabaff changed the title MQTT binary_sensor: Make variable `entity_id` available to value_template Make variable `entity_id` available to value_template for MQTT binary sensor Dec 12, 2018

Copy link

balloob left a comment

Ok to merge when test added.

@emontnemery emontnemery force-pushed the emontnemery:mqtt_binary_sensor_value_template_entity branch from 84bef02 to a18f98a Dec 12, 2018

@balloob balloob merged commit b97f0c0 into home-assistant:dev Dec 14, 2018

3 checks passed

Hound No violations found. Woof!
continuous-integration/travis-ci/pr The Travis CI build passed
coverage/coveralls First build on mqtt_binary_sensor_value_template_entity at 92.902%

@wafflebot wafflebot bot removed the in progress label Dec 14, 2018

mxworm added a commit to mxworm/home-assistant that referenced this pull request Dec 14, 2018

Merge branch 'dev' into current
* dev: (88 commits)
  huawei_lte: Fetch only required data (home-assistant#17618)
  Adding support for Plum Lightpad (home-assistant#16576)
  Fix restore state for manual alarm control panel (home-assistant#19284)
  Set InsteonEntity name to be combo of description and address. (home-assistant#17262)
  Device config for Fibaro hub integration (home-assistant#19171)
  Add air pollutants component (home-assistant#18707)
  Updated ELIQ Online sensor to async API (home-assistant#19248)
  Set unavailable when unreachable (home-assistant#19012)
  Make variable `entity_id` available to value_template for MQTT binary sensor (home-assistant#19195)
  home-assistant#17333: update to use DOMAIN constants and standards. (home-assistant#19242)
  Fix race in entity_platform.async_add_entities (home-assistant#19222)
  Fix race in entity_platform.async_add_entities (home-assistant#19222)
  Bumped version to 0.84.2
  Fix call to super() (home-assistant#19279)
  Fix OwnTracks deadlocking (home-assistant#19260)
  Fix list (fixes home-assistant#19235) (home-assistant#19258)
  Add automation and script events to logbook filter events (home-assistant#19253)
  Bump aioasuswrt (home-assistant#19229)
  Review comments
  Move check to websocket

@emontnemery emontnemery deleted the emontnemery:mqtt_binary_sensor_value_template_entity branch Dec 19, 2018

dshokouhi added a commit to dshokouhi/home-assistant that referenced this pull request Dec 25, 2018

Make variable `entity_id` available to value_template for MQTT binary…
… sensor (home-assistant#19195)

* MQTT binary_sensor: Make variable `entity_id` available to value_template

* Review comments

* Add testcase

@emontnemery emontnemery referenced this pull request Jan 2, 2019


Update binary_sensor.mqtt.markdown for #19195 #8021

2 of 2 tasks complete

@balloob balloob referenced this pull request Jan 10, 2019


0.85.0 #19897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment