How do I properly setup automation?

Could you please help me properly automation? Because the one I have does not work.

Situation - I have Aqara temp sensor in the room. I have a Sonoff switch in the same room which has a space heater attached to it.

I want the Sonoff switch to turn on when the current reading of the Aqara temp is 62.8F of lower.

I have setup the trigger the following way, but it does not work.

Second, a related question is - how do I debug the automation? Is there a way to emulate conditions, etc?

Thanks

An automation has three parts (that you need to worry about for now).

  1. Something that triggers the automation,
  2. something that validates if everything is in place or conditions are okay to continue for the action of the automation, and
  3. the actual action

You “have to” have at least 1. and 3. defined. It appears your automation only defines the trigger.

So in your case what is the trigger? The trigger is the Aqara - master bedroom temperature is below 62.8F (presuming this is F, and not Celsius, Kelvin, or Rankine).

What are the conditions you have where even though the temperature is below 62.8F you would want to turn on the heater?

For example, you are not home, or the sun is below the horizon (like chilly bedroom), or the electric rate is too high, or… anything you can think of. Those could be reasons not to turn on the heater.

So -
.a Trigger: The temperature is below 62.8F!

.b Condition: the heater switch is not ON, AND
.c.1. Condition: @invisible999 is home, OR
.c.2. Condition: Spouse is home

.c Actions: Turn the switch ON

Here is a simple example where HA turns on a switch (which is connected to a light) if there is motion.

My Trigger is a motion sensor called (suprisingly) MotionSensor1. If it detects motion, it drops to Conditions.

For me, I check two things, if I am home (Confirm info4hx4 is home) AND the switch, in this case PlugRelay2 is off. If BOTH are true (notice the little indentation of the two and the line Test if 2 conditions match preceded with an &), then Actions!

My Actions is simple, just turn on the PlugRelay2, which happens to be a plug relay that has a light stuck in it.


I suggest you skip the Conditions to try it out first. If that works, you can weave into it all kinds of Conditions. A neat little feature is that you can execute the Actions by clicking the triple-vertical-bubbles on the line where it says (for me) Turn on PlugRelay2 Switch, and selecting Run. Helps checking if you have the right entity.
You can also check if the Conditions are true, at individual row level, or overall, by selecting Test in the right of Test if 2 conditions match, or at the individual condition’s triple-bubbles.

Hope this helps.

You could also consider using the thermostat integration which provides the kind of functionality you want and more.

Thermostat

I’m going to assume that you actually do have actions in the automation (or it wouldn’t validate and load) and you are just showing us the trigger…

What is the temperature right now?

if it’s already below 62.8 then the automation won’t trigger. The state needs to go from above 62.8 to below 62.8 (transition) before the trigger will fire.

generally triggers need to go from false to true before they actually fire. going from true to true won’t work.

1 Like

Obviously, my automation has the action which is to turn the switch on. I did not include it because the screen was not big enough.

My point is - when temp drops below the threshold, automation did not start. Why?

Aha, we are getting here. The thing is, it is below 62.8F now - shows 61F.
My question is - how I can define a trigger that will start the switch regardless of what temp is now or has been, as long as it is below 62.8F?

That should only ever be an issue when you first create the automation. Once the automation is created and running then the trigger will work as expected once the temp goes above the set value.

So you can just leave the automation as is and wait for the temp to go above the set value and then go back below it. then the automation should run as expected.

But if you are going to also need to have an automation to turn the heater off once the temp goes above your desired value. And you have to be sure that value will be above 62.8 to enable the turn on automation to set up to re-trigger once it goes below again.

Turning off the heater is defined and works - I have a setup that it will turn off the switch once temp is reached 65F or if the switch has been on for 20 min. And it works - once I manually turn the switch on, after 20 min it turns itself off.

The problem is that the start of the heater does not fire and I don’t know why.

Has the temp ever been above 62.8 degrees since you have been testing the automation?

It’s also difficult to say exactly why it might not be working since we are only seeing the trigger portion. Thee may be other reason’s it’s not working that we don’t know about.

post the entire automation using yaml (there’s a way to copy the yaml from the automation editor but I don’t remember how since I never use the UI for creating automations) and make sure you properly format it by using ``` on the line before and after the code block.

I have no idea what you have in the automation in the part that I did not see :wink:

Set a time pattern trigger. Just trigger every 15 minutes (?), then add the condition of temp is below 62.8F, otherwise exit.

Brute forced, but works.

Set a Numeric state trigger so the heater switch is triggered any time it is below the value, not just when it is crossing it.

A bit more elegant.

- id: '1667533151548'
  alias: Turn on master bedroom heater
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.aqara_master_bedroom_temperature
    for:
      hours: 0
      minutes: 10
      seconds: 0
    attribute: temperature
    below: '62.8'
  condition:
  - condition: time
    before: '23:59:00'
    after: '17:00:00'
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - type: turn_on
    device_id: 9997f18f940f1513f6c01eacf75130e8
    entity_id: switch.master_bedroom_smart_plug
    domain: switch
  mode: single

Currently, it is 7:45PM and Aqara temp sensor reading is 62.1F

Once I setup the automation, the temp has been around 60-62F but not above 62.8F

Then it will never trigger. Not until it goes above 62.8 and then goes below 62.8.

Can you not just turn on the heater until it goes above 62.8 then turn it back off? :man_shrugging:

then when it goes below it should trigger.

Hm. That’s exactly what I did and now it is working.

My question is - how to setup a trigger that will fire the automation regardless of what temp was before, but rather what is now?

AFAIK you can’t unless you use a “automations reloaded” event trigger and make sure you check the conditions properly in the automation.

this usually isn’t an issue except in a few edge cases like yours. So it’s just easier knowing the limitation and resolving it like you just did.

The thing is - now it is working (need to watch), but I want to have the condition that it is working only during mon-fri and on weekends when no one is in the room temp can drop below 55.

Will the automation work for the case above?

I assume you mean if the temp is already below 62.8 and then one of the other conditions becomes true you want it to turn on the heater?

Typically to solve that problem you will need to add those conditions as triggers and then add the temp as a condition as well.

so you will have three triggers (temp, time, day of week) and three conditions (temp, time, day of week).