How to invoke automation at value update

Can anybody give me a hint, what I am doing wrong. I want to invoke a MQTT Message when a Value (mileage of my car) is changing. I made thist config, but it only works at the configured time at 23:59h. There is no update when the mileage is going up.

Any hints what I did wrong, may be the uper and lower values, but they make not realy sense in this context.

Thanks in advance

Hi and welcome to the forum.

Can you please share the YAML config for this automation?

Correctly formatted for the forum (see point 11 here).

Here you can find the YAML Code of the automation:

alias: 'Audi KM Stand Änderung '
description: Audi KM Stand Änderung zu IP Symcon
trigger:
  - type: value
    platform: device
    device_id: f702140dd6727c59e1d75c9879f72301
    entity_id: sensor.audi_a6_55_tfsie_mileage
    domain: sensor
    above: 1
    id: sensor.audi_a6_55_tfsie_mileage
  - platform: time
    at: '23:59'
condition: []
action:
  - service: mqtt.publish
    data:
      payload_template: '{{ states.sensor.audi_a6_55_tfsie_mileage.state }}'
      topic: /home-assistant/audi/mileage
mode: single

This trigger:

  - type: value
    platform: device
    device_id: f702140dd6727c59e1d75c9879f72301
    entity_id: sensor.audi_a6_55_tfsie_mileage
    domain: sensor
    above: 1
    id: sensor.audi_a6_55_tfsie_mileage

will only fire when the value crosses from below 1 to above 1. Going from 4 to 5 for example will not cause it to fire.

If you want to trigger on every change, use this trigger:

  - type: value
    platform: state
    entity_id: sensor.audi_a6_55_tfsie_mileage

This will fire every time the state (or any of the sensor’s attributes) changes. If the attribute changes are an issue we can add a condition to reject that.

I changed to this:

alias: 'Audi KM Stand Änderung '
description: Audi KM Stand Änderung zu IP Symcon
trigger:
  - type: value
    platform: state
    entity_id: sensor.audi_a6_55_tfsie_mileage
  - platform: time
    at: '23:59'
condition: []
action:
  - service: mqtt.publish
    data:
      payload_template: '{{ states.sensor.audi_a6_55_tfsie_mileage.state }}'
      topic: /home-assistant/audi/mileage
mode: single

And get the error message: Message malformed: extra keys not allowed @ data[‘type’]

Sorry I edited the device trigger incorrectly, try this:

trigger:
  - platform: state
    entity_id: sensor.audi_a6_55_tfsie_mileage
  - platform: time
    at: '23:59'
1 Like

Perfect, now it works! THX