---
title: "Automation fires at the wrong time"
category: "code"
id: 21643681-c59a-4547-9411-571bab7e66a1
canonical: https://solvedlist.com/solutions/automation-fires-at-the-wrong-time
---

# Automation fires at the wrong time

> Explains why a Home Assistant automation may fire at the wrong time due to silent template errors and how to fix it.

## Question

Why does a Home Assistant automation fire at the wrong hour despite a correct-looking time condition in the template

## Solution

Symptom: An automation fires at the wrong time (in the recorded case it switched all lights off at 23:32) although the template condition looks correct. Nothing in the log.

Cause: A Jinja template that throws during rendering is treated by Home Assistant as `false`, not as an error. The automation then runs into the else/default branch. Classic: `now().time() < today_at("23:00")` compares a `time` object with a `datetime` and raises `TypeError`; the condition is silently false.

Fix and prevention: check every condition individually against the template API before saving:

curl -s -X POST -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -d '{"template":"{{ now().hour >= 18 }}"}' http://<ha>:8123/api/template

The response is plain text (`True`/`False`), on failure `Error rendering template: TypeError ...`. Rewrite the condition so both sides have the same type (`now().hour >= 18` instead of a time comparison), and guard the else branch with an explicit condition as well.

Verification: query the template API for several hours (06, 12, 17, 18 and 23) and watch the automation in the logbook afterwards.

Note: a broken condition is not "randomly wrong", it is wrong by design. The else branch is where the damage happens.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
