Help with condition needed

I want to log recieved MQTT messages from my rflink to a file.

Working config :

configuration.yaml

notify:
  - name: NOTIFIER_rflink
    platform: file
    filename: rflink.txt

automation.yaml :

- id: '1569567613274'
  alias: rflink_log
  trigger:
  - platform: mqtt
    topic: rflink/#
  condition: []
  action:
  - data_template:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'
    service: notify.notifier_rflink

received log (partial) :

Home Assistant notifications (Log started: 2019-09-27T18:06:01.355407+00:00)
--------------------------------------------------------------------------------
2019-9-27 20:6:1 -> rflink/online - 1
2019-9-27 20:9:9 -> rflink/uptime - 1405
2019-9-27 20:13:26 -> rflink/online - 1
2019-9-27 20:14:9 -> rflink/uptime - 1410
2019-9-27 20:16:6 -> rflink/NewKaku-03a0b800 - {'SWITCH': '5', 'CMD': 'ON', 'SWITCH5': 'ON'}
2019-9-27 20:16:9 -> rflink/NewKaku-03a0b800 - {'SWITCH': '5', 'CMD': 'ON', 'SWITCH5': 'ON'}
2019-9-27 20:16:50 -> rflink/NewKaku-03a0b800 - {'SWITCH': '2', 'CMD': 'ON', 'SWITCH2': 'ON'}
2019-9-27 20:19:9 -> rflink/uptime - 1415
2019-9-27 20:24:9 -> rflink/uptime - 1420
2019-9-27 20:29:9 -> rflink/uptime - 1425

I’m not interested in the uptime messages, but when I modify my automation to this :

- id: '1569567613274'
  alias: rflink_log
  trigger:
  - platform: mqtt
    topic: rflink/#
  condition:
  - condition: template
    value_template: '{{trigger.topic}} != ''rflink/uptime'''
  action:
  - data_template:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'
    service: notify.notifier_rflink

I don’t receive any log messages anymore. So there is something wrong with my condition, but I can’t figure it out.

value_template: "{{trigger.topic != 'rflink/uptime' }}"

Thanks, but still not receiving anything in the log with this template.

Can you paste your full condition?

tried this one :

- id: '1569567613274'
  alias: rflink_log
  trigger:
  - platform: mqtt
    topic: rflink/#
  condition:
  - condition: template
    value_template: '{{trigger.topic}} != ''rflink/uptime'''
  action:
  - data_template:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'
    service: notify.notifier_rflink

and this one :

- id: '1569567613274'
  alias: rflink_log
  trigger:
  - platform: mqtt
    topic: rflink/#
  condition:
  - condition: template
    value_template: '{{trigger.topic}} != "rflink/uptime" '
  action:
  - data_template:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'
    service: notify.notifier_rflink

and this one :

- id: '1569567613274'
  alias: rflink_log
  trigger:
  - platform: mqtt
    topic: rflink/#
  condition:
  - condition: template
    value_template: "{{trigger.topic}} != 'rflink/uptime' "
  action:
  - data_template:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'
    service: notify.notifier_rflink

None of those are what I wrote. Try what I posted:

  condition:
  - condition: template
    value_template: "{{trigger.topic != 'rflink/uptime' }}"
1 Like

Will try this .

Thanks. Got it working !!!

(I don’t know why, but the automation editor add extra ’ in the template)