core: Automation not always triggered with value_template although the state changed

The problem

I have an automation to turn a light on and off when I am connected to a certain AP Mac address. Even tough that I can see by printing {{ state_attr('device_tracker.iphone11', 'ap_mac') }} that the Mac address is the one that should trigger the action, sometimes it is not triggered.

Environment

HA version 0.105.5 Operating environment: Docker

  • Home Assistant release with the issue:
  • Last working Home Assistant release (if known): NA
  • Operating environment (Hass.io/Docker/Windows/etc.): Docker
  • Integration causing this issue: automations
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/automation/

Problem-relevant configuration.yaml

- id: ga.light.on
  alias: light on
  trigger:
  - platform: template
    value_template: "{% if is_state_attr('device_tracker.iphone11', 'ap_mac', '18:e8:29:93:f4:ea') %} True {% else %} False {% endif %}"
  condition: []
  action:
  - data:
      payload: 'on'
      topic: shellies/shelly1pm-B1E13B/relay/0/command
    service: mqtt.publish

Traceback/Error logs


Additional information

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

@dshokouhi please be careful with what you’re saying here. @mamartins is using a multiline ( >) template and as such his template is just fine, albeit with a bit extra white space between the curly brackets. Then again these are taken out by the >-

- platform: template
  sensors:
    at_garage:
      device_class: occupancy
      friendly_name: "At garage"
      value_template: >-
        {{is_state_attr('device_tracker.iphone11', 'ap_mac', '18:e8:29:93:f4:ea')}}

is just perfectly fine. (from a templating point of view, not speaking of the actual values used or unify integration functionality)