Hi there,
I am trying to create a simple automation with 3 condition for a DHT11 sensor. One condition is OK by the way.
the condition trigger a light when it is below 23 C or above 25 using MQTT protocol.
I started testing automations but I dont find how configure OR conditional. then I decide to configure manually. Please guys you would give a light where it miss or the wrong configuration I am doing.
Thatâs not how conditions and action work together. Triggers, conditions and actions are on the same level, i.e. you can trigger an action if all conditions (or when using an or condition, any of the conditions in your list) are true.
trigger:
...
condition:
...
action:
...
You may need to split your configuration into three separate automations.
when I split conditions I found the problem that two the condition became âtrueâ. for example the rule over 23C sends OFF but over 25 sends ON and light flip ON and OFF each time sensor receives MQTT message.
I tested before post but I will tried again.
what I cannot figure out is how set an OR condition for my 3 rules.
What I meant is: you canât have one automation with two different actions depending on which conditions evaluate true or false.
Re-reading your automation attempt: You want a switch to turn off if the temperature is between 23 and 25 degrees, and you want that switch to turn on if the temperature is either below 23 or above 25 degrees.
Maybe, instead of conditions, you could try the template approach. Have an automation with just the trigger and an action, no conditions. The action would then look something like this (havenât tested this, so syntax may be slightly wrong):
I appreciate your response, it is accurate my situation. I tried to do with template however my IF sentences return a error, would you please give a look and enlighten me.
That template is all over the place and nowhere even close to how templates are used in homeassistant.
In general it is best not to try and run before you can walk.
Here is how to decide what builds a template:
First (1), you need to look at the logic of the situation. Then (2) work out what services are required for each potential outcome. Then (3) define which data is required to be passed to each service. Then (4) apply that to how homeassistant can receive the information.
(1) In your case the logic is fairly simple (assuming Iâve understood your post correctly).
If the temperature is 24 switch off both switches.
Or if it is above 25 turn one on. (elif)
If it is below 23 turn the other one on. (else, if itâs not 24 or above, it must be below)
(2) So your services are:
Turn on
Turn off
(3) And your data is:
the name of the switch. (depending on the temperature)
(4) Apply it to a homeassistant configuration:
So:
service_template: when this template resolves I want it to turn something on if it is not 24, but off if it is 24.
data_template: when this template resolves I want it to be the correct switch(es) based on the temperature.
thanks for your response and explanation.
I am using MQTT triggers because my lights and sensor are setting in ESP32.
I searched ways to set them and found it no complicate it.
back to your approach, if it use states for automation, it does not need trigger and conditions, does it?
trigger:
platform: state
entity_id: sensor.temperatura
With no conditions.
This way every time the reading of the sensor changes it will run the automation, and if it is under 24 the correct fan will turn on (if it is already on because the previous temperature was already under 24 then it will just stay on). If it is over 24 same principle, and at 24 switch them off.
It doesnât matter that the sensor is set via mqtt, once it is set it has a state and once that state is different to last time is when we want to trigger the automation.
I tried hard with configuration for some hours without success, it seems that missing entity_ID even they are on it. The automation display this error:
Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token âend of statement blockâ, got âstatesâ) for dictionary value @ data[âactionâ][0][âdata_templateâ][âentity_idâ].
I tried with enclose entities in " or â or { } and [ ] but any result. I did a small change for float values, but error displayed is same with |int.