Issues with conditions for an automation

Hi there,

I want to sent a notification, when my coffeemachine finished with making me a coffee.
Unfortunately, the conditions are a bit more difficult than I thought - due to the fact how the whole integration works… :frowning:

First thing to know - it is a HomeConnect device, and I am using the home connect alt integration from HACS - not the default HomeConnect integration (with which I could do the automation - but with way less information… and the default integration is not as comfortable as the alternate integration…

OK, back to the topic.
The rules for such an automation should be pretty straight forward:

  • Check if program has finished
  • Send a persistant notification.

Now to the more complex part:

  1. We do have a “Select Program” - with which I can decide, if I want a coffee, or an espresso, or what ever else the machine can do.
  2. We do have a Sensor “Active Program” - which does show the selected program.
  3. We do have a parameter to show if a program is running - the operation state…

When the machine is “idle” - means, no program is running, the “selected program” from the select option does show the current selected program (e.g. Coffee, Espresso, …)
The “Active Program” has the state “unknown”.

Now, when I start the machine, the “selected program” becomes unknown - but the active program will show what the machine is currently doing… (Coffee, Espresso,…)

The Operational State is “running”.

As soon, as the Operational state is switching to “finished” - I want to display a notification with the content of the “active program”…

BUT: just with switching the Operation State to finished, the active program becomes “unknown” - and the selected program becomes the value of your selection…
Now, I could display the ‘selected program’ instead of the active program - but this would mean, that the Selected program might have changed - and therefore, it COULD display the wrong value.

I’ve debuged my automation in a way - that I am checking for conditions (after getting no notifications for a while)… and the automation always failed for the check: “if active program NOT unknown”…

Anyone an idea, how I could get the value of the “active program” just before it switched to unknown?

Trigger:

Condition #1 (not “unavailable”)

Condition #2 (not “unkown”)

Condition #3 + #4 (not “CleaningOn” / “CleaningOff”)

Action: Do some translation and send the notification:

Automation YAML:

alias: "notification: Kaffee ist fertig"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.siemens_ti9578x1de_68a40e8445de_bsh_common_status_operationstate
    to: BSH.Common.EnumType.OperationState.Finished
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.siemens_ti9578x1de_68a40e8445de_active_program
        state: unavailable
    alias: Test if not "unavailable"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.siemens_ti9578x1de_68a40e8445de_active_program
        state: unknown
    alias: Test if not "unknown"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.siemens_ti9578x1de_68a40e8445de_active_program
        state: ConsumerProducts.CoffeeMaker.Program.CleaningModes.ApplianceOffRinsing
    alias: Test if not "ApplianceOffRinsing"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.siemens_ti9578x1de_68a40e8445de_active_program
        state: ConsumerProducts.CoffeeMaker.Program.CleaningModes.ApplianceOnRinsing
    alias: Test if not "ApplianceOnRinsing"
action:
  - service: notify.persistent_notification
    data:
      title: Benachrichtigung von Siemens EQ.9
      message: >-
        {% set Enum_program_type =
        states('sensor.siemens_ti9578x1de_68a40e8445de_active_program_program')
        %} {% set Program = {
        "ConsumerProducts.CoffeeMaker.Program.Beverage.CaffeLatte":
        "Milchkaffee",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.Cappuccino": "Cappuccino",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.Coffee": "Caffè Crema",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.Espresso": "Espresso",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.EspressoDoppio": "Espresso doppio",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.EspressoMacchiato": "Espresso Macchiato",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.LatteMacchiato": "Latte Macchiato",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.MilkFroth": "Milchschaum",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.Ristretto": "Ristretto",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.WarmMilk": "Warme Milch",
          "ConsumerProducts.CoffeeMaker.Program.Beverage.XLCoffee": "Kaffee XL",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Americano": "Americano",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.BlackEye": "Black Eye",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.CafeAuLait": "Café au lait",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.CafeConLeche": "Café con leche",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.CafeCortado": "Café cortado",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Cortado": "Cortado",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.DeadEye": "Dead Eye",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Doppio": "Doppio",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.FlatWhite": "Flat White",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Galao": "Galão",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Garoto": "Garoto",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.GrosserBrauner": "Großer Brauner",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Kaapi": "Kaapi",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.KleinerBrauner": "Kleiner Brauner",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.KoffieVerkeerd": "Koffie verkeerd",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.RedEye": "Red Eye",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.Verlaengerter": "Verlängerter",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.VerlaengerterBraun": "Verlängerter braun",
          "ConsumerProducts.CoffeeMaker.Program.CoffeeWorld.WienerMelange": "Wiener Melange" } %}

         {{ Program[Enum_program_type] if Enum_program_type in Program.keys() else states('sensor.siemens_ti9578x1de_68a40e8445de_selected_program') }} ist fertig.
mode: single

```

Me again… immediately after the coffeemaker has finished the automation sends a notification. Maybe I don’t see the trap, but is it realistic that the program will be changed within this timeframe?

exactly.
The program will change from “Coffee” to “unknown” immediately, when the operating state will change to “finish” - which means, the condition for “unknown” will be met - and the automation will not be triggered.

Yes, but the selected program is still available.

selected program is unknown (in HA) as long as the program is running.
It will become “known” - when the program finished… but can be asured, that “selected” program is still the program that was selected when the machine was started?

In theory, it COULD be - that the selection might change (on the device itself, maybe)
Then, the output / notification could show the wrong program selection… you know what I mean?

Somehow, I would consider a way to “store” the last “active program” while the program was running - and then display this stored value - before the active program will change to uknown…

Maybe, I need to use third party integrations, such as “variable” - to store the state?
(now, that I am thinking of it)

We are talking about milliseconds between program end and message. However, if someone tries to fool you and changes the running program, you will notice it anyway. :wink:

Of course you can create a template sensor as an alterna.

A triggered template sensor could do this for you.

State Trigger: Operational State → running

State: Active Program value.

1 Like

ok, thanks - I’ll try it with triggered template sensors…
For a while now, I had a HA installation running, which was barely used with all it’s power.

Since it became more and more blowted to display (unnecessary information) it was now time to throw everything away and start a new setup - where I want to use more and more of the functional stuff from HA…

It seems, that there is still a long way to go - and learn all that stuff :smiley:

Hi tom_I,

can you may have a look, if this seems to be correct in your eyes?

  - trigger:
      - platform: state
        entity_id:
        - sensor.siemens_ti9578x1de_68a40e8445de_bsh_common_status_operationstate
        to: BSH.Common.EnumType.OperationState.Run
    sensor:
      - name: 'Coffeemachine_Active_ProgramRunning'
        unique_id: 'Coffeemachine_Active_ProgramRunning'
        state: "{{ states('sensor.siemens_ti9578x1de_68a40e8445de_active_program') }}"