From template editor to configuration.yaml

My washing machine is stating “unavailable” when the power is off, so I thought I would use this if state to either have On or Off for that entity. This one works great in the template editor, but how would it look if I want to put it in the configuration.yaml file?

{% if states (“sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate”) == unavailable %}
On
{% else %}
Off
{% endif %}

Just to be clear, you don’t modify the washing machine sensor entity… Template sensors and binary sensor are separate entities.

Not sure I understand, but I need to create a new sensor like “wash status” that will track the washing machines status?

Yes. That can be accomplished with a YAML-configured Template sensor or binary sensor as shown in the documentation I linked above or through a Template Helper set up in the UI.

I tried this but got errors:

Template:
-binary_sensor:
-name: “washing machine”
state: >
{% if is_state (“sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate”) == unavailable %}
On
{% else %}
Off
{% endif %}

It would be very helpful, if you could take a look at this topic:

It helps us, to help you. In your case, please format the code, and provide us with details like an error message. :slight_smile:

Thanks a lot!

There are a couple definite errors, but as Patrick stated we need specific information to give you specific answers.

When you say “I tried this…” what do you mean? Did you paste that in your configuration exactly as shown or are you using the Template Helper editor?

Is unavailable the only value that should make the sensor render on?


The basic YAML configuration would be as follows, the if/else is unecessary:

template:
  - binary_sensor:
      - name: “washing machine”
        state: >
          {{ is_state('sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate', 'unavailable') }}

OK, sorry for the badly put questions, I was doing it via my tablet, not a good idea maybe… So here goes, from the begining:

I have the Home Connect Alt integration with the devices Dishwasher ang Washing machine. The dishwasher is working properly when off, but the washing machine just states ‘unavailable’ when the power is off. This is my cards in my dashboard when both machines are off:
image

That is why I was looking for the solution to make the statement ‘unavailable’ to say ‘Off’ instead, to make it more proper in the card.

This code (inserted in configuration.yaml) gives the code ‘On’ at my Card, even if the washing machine is off…

template:
  - binary_sensor:
      - name: “washing machine”
        state: >
          {{ is_state('sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate', 'unavailable') }}

That was the logic you had in your second post.

So, you want “unavailable” to return “off”; are there any other values that should return “off”.

Should all values other than “unavailable” just be returned as-is, or do they need to be modified as well? Keep in mind that only certain values, True, yes, on, enable or positive numbers, are rendered as “on” in a binary sensor.

No, it looks like the washing machine only have those two states, on or unavailable.

What should happen if the original sensor is unknown? I would suggest you set that as the availability determining value, so you have an indicator that there is something wrong with the source sensor:

template:
  - binary_sensor:
      - name: “washing machine”
        state: "{{ is_state('sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate', 'on') }}"
        availability: "{{ not is_state('sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate', 'unknown') }}"

Now it just shows Off, even when turned on. Original sensor returns On, but binary does not.

Try something like this.

template:
  - binary_sensor:
      - name: “washing machine”
        state: "{{ not states('sensor.siemens_wm14pihdn_68a40e60a7cb_bsh_common_setting_powerstate') in ('unavailable', 'unknown') }}"

Would also add, if you are not overly comfortable with adding sensors in yaml or just need a simple template sensor, you can use the template helper (just copy the bit in the curly brackets, including curly brackets) into the template line of the helper config.

Settings → Devices and Services → Helpers

Wow, thanks! It looks perfect. Thanks also to Didgeridrew for helping :slight_smile: As you can see I am pretty new at HA but this has been a good lesson for me.

Cheers guys :+1:

1 Like

Just to note, what you’re doing here is not best practice in general. :slight_smile:

If an entity is unavailable, it normally does have reasons. In this specific case it seems like an error on the manufacturer side, as off should be off and not unavailable. Perfectly valid in this case, but shouldn’t be used otherwise… :smiley:

Be careful with such things, they tend to haunt you later on… :laughing:

And if I may offer one piece of really important advice: start now with something like a naming convention! You will get annoyed in the future, if you use such names like shown in your first post. :slight_smile: I know, this is tedious, but the best way to handle this is with every new device, on first discovery, give it a name you can work with. Shorter and meaningful is the way you want. :slight_smile:

It is an error from the manufacture, others have problems with the Siemens appliances according to the forum, so this is the best solution for me at the moment.

Actually , I have another friendly name for the entity, but it is in Swedish so I copied the original name for my first post :wink:

Thanks anyway for the advices, appreciate it! :grinning: :+1:

1 Like