Automation trigger strange behaviour

How?
I have also this sensor:

- platform: template
  sensors:
    date_month:
      entity_id: sensor.time__date
      friendly_name: 'Corrente Mese'
      value_template: >
        {{as_timestamp(now()) | timestamp_custom('%B', True)}}

This doesn’t give me errors and it’s pretty similar to the first…
How to use sensor.time__date ?

Well, I don’t know to be honest. I’m not sure why it’s failing for you. I was just giving a possible solution. To be quite honest, it should work without fail.

Do you have the sensor.time__date properly defined in your config?

- platform: time_date
  display_options:
    - 'time_date'

Note that in the definition it’s time_date (one ‘_’) while the sensor shows up as sensor.time__date (with 2 ‘__’).

Yes, i don’t know why but the sensor has double underscore, while in the config i have one… really strange, but true!

@123 @petro Sorry, but the automation still doesn’t work… this morning the motion sensor was triggered before 8:30 and after 8:30 and in both cases the automation did not started…
I see i had a custom_ui to put in the attributes of all automations the value of the last time it was triggered. I removed it but still doesn’t work. I also see (without custom_ui) the last_triggered attribute was set to ‘null’ after a restart of HA.
What do you think ?

Well yeah, thats because you don’t have a last triggered on that automation: automation.meteo_ed_agenda. So your problem is with that automation, not with the automation we helped you with.

Wait a minute, you can’t reference the automation you are inside… Last triggered will always be zero. Your logic is flawed there.

But it was the automation i asked help…

So, if your automation triggers, when you check the condition now()-last_triggered will always be zero. We fixed your issue but now your own logic is causing the problem. Last_triggered is not the 2nd to last trigger. It’s literally the last time the automation was triggered, which is now().

Hmmm… the automation did not started as expected… i restarted many times HA and since last time the last_triggered attribute is always null… maybe i don’t understand you completely, sorry for my poor english…
I just want the automation work as expected…

If the automation triggers. Last trigger gets set to now(). Then you subtract now()-last_triggered. That will always be 0 seconds.

So what to do for automation working? Is your template good for this ?

Why even have the template?

Hmmm good question… i just copied this automation from another user and tried to make it working for my automation… Please, if you have time, correct my automation to work as i expect…

I’m not sure exactly what you want

Ok, i want this automation running a script or something else only between 8:30 and 10:00 when the motion sensor is activated…

Ok, and you want it running multiple times or just once?

just once… so that’s why that template… or am i wrong?

Ok, just add a counter and reset it at midnight.

counter component that needs to be placed in configuration.yaml.

counter:
  meteo_ed_agenda:
    initial: 0
    step: 1

your automation.

- alias: Meteo ed Agenda
  trigger:
    - platform: state
      entity_id: input_boolean.mauhome
      to: 'on'
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0001a92ca1
      to: 'on'
  condition:
    - condition: time
      after: '08:30'
      before: '10:00'
    - condition: state
      entity_id: counter.meteo_ed_agenda
      state: 0
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.googlehome0461
        volume_level: 0.50 
    - service: tts.google_say
      data_template:
        entity_id: media_player.googlehome0461
        message: >-
    - service: counter.increment
      entity_id: counter.meteo_ed_agenda

Reset the counter at midnight.

alias: reset meteo ed agenda counter
  trigger: 
    platform: time
    at: "00:00:00"
  action:
    service: counter.reset
    entity_id: counter.meteo_ed_agenda

Ok many thanks… i’ll test it and let you know…