Automation issues with mqtt rules

Hi,
As I am new to HA firstly I would like say - HA is great product and thanks to everyone involved.
Now about issue I am facing - I created simple automation rule that is based on average temperature and day/night powers on or off Sonoff trough mqtt. When HA is restarted automation rules is working for some time and then just stops, so I configured Telegram bot and new temp rule to send update every hour about status and avg temp. Temp rule is working ok after restart but actual mqtt rule is stopping after some time. Tried to enable debug for automation but no results there.
I`m using HA 0.82.1 in docker.
Logs - link to automation cfg, HA logs and ha telegram bot log
Any advice where to dig would be greatly appreciated!

I’ve not looked in details but I don’t believe this will work:

    - condition: time
      after: '23:00:00'
      before: '06:00:00'

you’d need 2 conditions:

    - condition: or
      conditions:
      - condition: time
        after: '23:00:00'
      - condition: time
        before: '06:00:00'

Confusing thing that it works after restart for some time, but thanks for hint - will try your suggestion.

yeah not sure either why, “at first glance” it looks ok. Only thing I can think of are the conditions that would stop it from working.
Actually you could manually run the automation when it fails to automatically to see if the issue is linked to actions or trigger/conditions

Hi @lolouk44, according to the docs, the condition should work.

Time condition windows can span across the midnight threshold. In the example above, the condition window is from 3pm to 2am.

Thanks for pointing this out @VDRainer. Guess that must have changed since the last time I had such an automation

So condition should not be an issue here right? I have not restarted HA yet, so I is in not working state now and threshold values are almost reached, so I could test any suggestions. About manual trigger of automation - any pointers how to achieve it? I looked at “States” page and all automation states are on, so is there any point of triggering them to “on” again? And I can also change state for Sonoff (mqtt) from GUI also and it works. So I am out of ideas what else to try.

If you click on the ‘More Info’ link of the automation in ‘States’ you can switch the automation on/off an also start the action part of the automation.
Auswahl_006

Bad news - automation trigger worked as expected without intervention. Will try to catch next time when rigger will fail and will try to “trigger” it manually and then will report back results.
Now it looks like when I poke around in GUI then trigger is working but when left alone for about a day, one trigger starts to fail :frowning:
Thanks!

The state that you see there isn’t that the automation is running. It’s telling you that the automation is available to be triggered by the things defined in your trigger section. If that was “off” then the automation would not run even if the trigger events and conditions were all true.

At night again automation task was not executed. When manually triggered then heating was powered off so I guess that means that with automation task all is good, only question then remains why it is not triggered. Nothing interesting in logs either. So to sum up - issue still exists.

try removing the quote marks from your numbers in all the trigger sections:

trigger:
  - below: 17
    entity_id: sensor.avgkitchentemp
    platform: numeric_state

I’m pretty sure the numeric_state trigger is looking for a actual number. When you put stuff in quotes I think you turn it into a string which won’t ever be a number so it never triggers.

Tnx for suggestion

Looks like sensor value is not a number (tried to paste {{ states.sensor.avgkitchentemp.state > 0 }} in Templates page and nothing is returned, but when added float then it is True). Value of sensor I get following way

- platform: min_max
    type: mean
    name: avgkitchentemp
    round_digits: 1
    entity_ids:
      - sensor.kitchen1_3
      - sensor.kitchen2_2 

So I did change automation triggers to

  trigger:
    - platform: template
      value_template: "{% if states.sensor.avgkitchentemp.state | float < 17 %} true {% endif %}"

Will see if it helps.

Specific automation rules worked again for about 24h and then stopped - this morning avg temp was bellow threshold so changed trigger did not help. Triggered again automation rule manually and it worked.

I think I know why.
the trigger will only work if the value goes above 17 and then below 17.
Say it does that while you’re in the excluded period (the 06:00 - 23:00 and vice versa), it won’t trigger again when it goes from [say] 16 to 15 or lower.
Best way would be to change your automation like this:

# Heating at day
- id: '1541944518140'
  alias: Heating on at day
  trigger:
  - entity_id: sensor.avgkitchentemp
    platform: state
  condition:
    - condition: template
      value_template: '{{ states("sensor.avgkitchentemp") | int < 17 }}'
    - condition: time
      after: '06:00:00'
      before: '23:00:00'
  action:
  - data:
      payload: 'on'
      topic: cmnd/S_virtuve1/power
    service: mqtt.publish
  - data:
      payload: 'on'
      topic: cmnd/S_virtuve2/power
    service: mqtt.publish
  - data:
      message: "Heating on at day"
    service: notify.send_telegram_to_bibo

This will make it trigger every time the sensor changes, not just when it goes from above 17 to below 17.

Tnx for suggestion, will try and report back.

That is odd, because I always understood from discussions on this forum that time conditions could not span midnight. That part of that page has not changed since it was first written, according to github.

Thanks, that’s also what I thought but @VDRainer commented otherwise above.

@BIBO
Try with the change in trigger and see if it works. If it doesn’t you may need to amend the condition as per my original post

You could also use a time trigger, e.g. every 5 mins, to do some kind of polling. This way you would generate a trigger even if the temperture is below threshold but not changing for a longer period after entering the desired time window.

Tnx lolouk44 your suggestion works. More than one day running without issues. Made few adjustments - changed int to float as I am dealing with decimal values and added additional conditions to check if heaters are on/off before triggering to prevent triggers multiple times.
eXtatic - idea about time based triggers also came to my mind, tnx!