Automation Syntax Help

Sorry for the generic title, not sure how else to summarize this.

I built a python script on a device on my network that sits behind a VPN. The python script calls my HA instance and updates an entity called vpn_ip. I put this in crontab and it runs every few minutes. When HA first starts, I set this value to unknown, and then on the next crontab run, it should update to the external IP address (I’m calling https://api.ipify.org?format=json in that script and it should respond back with the IP). If the vpn device cannot talk to the internet (ie - the VPN went down), the request will timeout, the VPN device then updates HA with a value of TIMEOUT. I have an automation (that works), which uses pushbullet to send a push if the status changes to TIMEOUT. I’m now trying to build a basic binary sensor that will show on/ or for the vpn status. I came up with this, but it’s not changing the status of the binary_sensor at all:

- id: '1573837112220'
  alias: VPN Up
  description: ''
  trigger:
  - entity_id: sensor.vpn_ip
    from: unknown
    platform: state
  condition: []
  action:
  - condition: state
    entity_id: binary_sensor.vpn_status
    state: >-
      '{%
      if 
        is_state('sensor.vpn_ip','unknown') or is_state('sensor.vpn_ip','TIMEOUT') or  is_state('sensor.vpn_ip','URL_ERROR')
      %}
        true
      {% else %}
        false
      {% endif %}'

I did the opposite on my existing automation (to: TIMEOUT), by adding a second action after the pushbullet call, but that isn’t working either. I’m not entirely sure what I have wrong, but I assume it’s in the state: element.

Thanks!

What kind of binary sensor is binary_sensor.vpn_status?

I don’t think you want an automation for this, you want a template binary sensor.

binary_sensor:
  - platform: template
    sensors:
      vpn_status:
        friendly_name: "VPN is down"
        value_template: >-
          {{ is_state('sensor.vpn_ip', 'unknown') or is_state('sensor.vpn_ip', 'TIMEOUT') or is_state('sensor.vpn_ip', 'URL_ERROR') }}

Ah! I had a typo in my config of the binary sensor element and was trying to solve it with automation, but that shouldn’t be necessary. Your post helped me see that. I now have the binary sensor defined like this:

binary_sensor:
  - platform: template
    sensors:
      vpn_status:
        friendly_name: 'VPN Status'
        value_template: >-
          {{ not ( is_state('sensor.vpn_ip', 'unknown') or is_state('sensor.vpn_ip', 'TIMEOUT') or is_state('sensor.vpn_ip', 'URL_ERROR') ) }}