Sensor output from english to another language for tts

made a small mistake, forgot the curly braces on the 2nd part of the if statement.
Try:

- platform: template
  sensors:
    zigbee_postkasten_contact_last_changed:
      entity_id: sensor.zigbee_postkasten_contact
      value_template: >-
        {% if (states("sensor.uptime") | float > 0.1)%}{{states.binary_sensor.zigbee_postkasten_contact.last_changed}}{% else %}{{states("sensor.zigbee_postkasten_contact_last_changed")}}{%endif%}

Ok, I tried that thanks, but the output in the dev templates section is still

states("sensor.zigbee_postkasten_contact_last_changed")

have you created a new template sensor called zigbee_postkasten_contact_last_changed?

Not with your newest code, I first checked it in the dev tools. But I will test it as a sensor now.

Sidenote:
About the UTC+2 thing. Found out that this was my own mistake. I set is um as “Zeit UTC+2” in customize using friendly name. And at the time I set this up it was summertime so it was right. I changed to “Zeit” now and this ends my confusion on that. :wink:

1 Like

ok so the output of that sensor is

unknown

it will the very first time you start as it’s not yet been initialised
Try to flicker your mailbox and then wait 5 min and restart and see what value it shows

Ok, but instead of manually flicking the lid, I will set the state in the dev tools. Because if I go out to flicker the lid to test it all the time now, neighbours will possible and legitimately think I’m done. :wink:

Edit: @lolouk44 Ok so unfortunately the state of the sensors stays unknown

ok, maybe the time to wait after start is too long
try and replace 0.1 with 0.01 in {% if (states("sensor.uptime") | float > 0.1)%}
enter this in your templates
{{ states("sensor.uptime") }} and as soon as the value is higher than 0.01 force the state change

Ok so I changed it to 0.01, restartet, changed the lid state a few times, restartet again and still unknown.

I don’t know what this does, but this

{{(states(“sensor.uptime”) | float )}}

out puts

0.0

And I want to add that I don’t have a sensor called sensor.uptime in my entity list.

Edit: will add this now

ok. Just tested on a test environment and it appears HA doesn’t like {% if (states("sensor.uptime") | float > 0.01)%}{{states.binary_sensor.zigbee_postkasten_contact.last_changed}}{% else %}{{states("sensor.zigbee_postkasten_contact_last_changed")}}{%endif%} as even when I fix the code (there was indeed an error in the template), HA sets the state to unknown at boot, even though I managed to set the correct last change value …
back to drawing board.

Add this to your config:

input_text:
  zigbee_postkasten_contact_last_changed:
    name: zigbee_postkasten_contact_last_changed

sensor:
  - platform: uptime
    unit_of_measurement: hours
  
automation:
  - alias: Save Zigbee Postkasten Contact Last Changed
    trigger:
      platform: state
      entity_id: binary_sensor.zigbee_postkasten_contact
    action:
      - service: input_text.set_value
        data_template:
          entity_id: input_text.zigbee_postkasten_contact_last_changed
          value: "{{ states.binary_sensor.zigbee_postkasten_contact.last_changed }}"

then replace your script with this:

routine_postkasten:
  sequence: 
    - service: media_player.alexa_tts
      data_template:
        entity_id: '{{ states.sensor.last_alexa.state }}'
        message: >
          {% if as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | default(0) | timestamp_custom("%H", true) | int >= 8 %}
            Post war heute um {{as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | timestamp_custom("%H", true) | int }} Uhr {{as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | timestamp_custom("%M", true) | int }} da
          {% else %}
            Post war heute noch nicht da

Ok thanks, I’ll try that out.

Two things:

First I’ll add a to: 'on' for the automation to save the state, because else unavailable will also change this.

And there is a {% endif %} missing in your script.

oops missed the last line in my copy/paste, well spotted.
the input_text defo works, I’ve tried it on my “lab” :slight_smile:

Ok, I did a frist test and I thing it works. Have to do some more tests to make it sure, but looks good. Thanks again!

Besides the time/date is saved in the input_text as UTC+0 right? Because there it doesn’t show the right time. But when I call alexa she tells be UTC+1. Again this is the “true” setting … i know.

But is there a way to see the sensor state in utc+1 too? Maybe I’ll add that sensor to my front UI too (but only if it show the “right” time).

timestamps are in UTC by default in HA.
If you want you can change the data saved in the input_text to be [h] Uhr [m] so you can see it and use it directly with Alexa.
Think I’ve given you enough weapons to blast this one off now :slight_smile:
Have fun

1 Like

Yeah you have. Thanks for your time. Hopefully you can use parts of your examples yourself.

Great work!

1 Like

Ok so this is what I added to add the sensor to my front ui

in sensor.yaml

- platform: template
  sensors:
    postkasten_time:
      entity_id: input_text.zigbee_postkasten_contact_last_changed
      value_template: >
        {{ (as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | timestamp_custom("%H", true) | int )}}:{{(as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | timestamp_custom("%M", true)) }}

in binary_sensor.yaml:

- platform: template
  sensors:
    postkasten_heute:
      value_template: >-
        {{ as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | default(0) | timestamp_custom("%H", true) | int >= 8 
            and (as_timestamp(now()) | timestamp_custom("%x", true) == as_timestamp(states("input_text.zigbee_postkasten_contact_last_changed")) | default(0) | timestamp_custom("%x", true)) }}

I’ll use the binary sensor for a conditional lovelace card, so show the above sensor only if the binary is true.
Because else it would show the time from the last day.

Suggestions are always welcome^^

In lovelace:

  - type: conditional
    conditions:
      - entity: binary_sensor.postkasten_heute
        state: "on"
      - entity: input_boolean.postkasten 
        state: "on"
    card:
      type: entities
      entities:
        - sensor.postkasten_time
        - entity: input_boolean.postkasten 
          name: Quittieren

I added that input_boolean to be able to close that window. And added to turn on the input_boolean when the automation above gets triggered. like this:

input_boolean:
  postkasten:

automation:
  - alias: Save Zigbee Postkasten Contact Last Changed
    trigger:
      platform: state
      entity_id: binary_sensor.zigbee_postkasten_contact
    action:
      - service: input_text.set_value
        data_template:
          entity_id: input_text.zigbee_postkasten_contact_last_changed
          value: "{{ states.binary_sensor.zigbee_postkasten_contact.last_changed }}"
      - service: homeassistant.turn_on
        entity_id: input_boolean.postkasten