Backward logic on automation

Tags: #<Tag:0x00007f3f1772b3b8>

Hi,

I really get frustated with the automation in Hassbian. It’s been almost 30 years since I worked with automation (professionally, building factories).

Even 30 years ago, when there was not much computer power it was easier than with hassbian.

You start with the trigger, the trigger is not a data type, it is what you call in home-assistant an entity.

I choose SMHI as an example.

First you choose the entity.

When you chosen the entity, in my example [weather.smhi_xxx], you chose the parameter in the entity, for SMHI the following parameters should be available (in a dropdown menu)

Weather Sunny /state
Temperature 18 °C /integer
Air pressure 1013 hPa /integer
Relative humidity 53 % /integer
Wind speed 4 km/h (SSV) /first part integer second part state
Visability 18.7 km /float

The type data for example ”string” (state), integer or float is known by the system. No need to choose that.

In an old PLC system in a simplest, form, you logically use “and” “or”, “exclusive or”, “bigger than”, “less than”.

I guess in home assistant, multiple triggers are “or” and conditions are “and”, there is no “Xor” as I can see it.

When selecting the result, again you should be able to choose the entity first and then a dropdown menu should display what options there is to change the state of that entity

Logically as an example;

If Shelly_H&T.xxx.temperature is higher than 23
Or
Ikea_trålös.xxx.switch=”on”
AND
weather.smhi_xxx,temperature is lower than 21
THEN
Set Shelly.switch.xxx to state “on” !Fan

The logic is there already, but starting with the datatype rather than the entity and its parameters (with datatypes) is backwards.

BR
Tobe

Not always. You can define a set of conditions as “or”.

https://www.home-assistant.io/docs/scripts/conditions/#or-condition

Correct. Not as such but you can create template conditions and make those function as “xor” but it does get cumbersome if you have very many conditions.

https://www.home-assistant.io/docs/scripts/conditions/#template-condition

I’m not following what you are saying here.

However, many people (including me) don’t use the automation editor because of several reasons including some that you stated. I just hand code everything in yaml. It’s less confusing.

Got that;

I’m not completely computer illiterate. Use to be a professional programmer, but somethings else happened the last decades😊

I believe I can learn YAML, but still I haven’t managed to figure out how to use an parameter in an entity as a trigger or condition as for example the temperature from weather.smhi_xxx,

This is the data in HA (there are more). But when looking at the state in HA, I can only Weather which in this case have the state sunny.

Weather Sunny /state
Temperature 18 °C /integer
Air pressure 1013 hPa /integer
Relative humidity 53 % /integer
Wind speed 4 km/h (SSV) /first part integer second part state
Visibility 18.7 km /float

I like to have temperature as a trigger or a condition. So far I haven’t found any info on how to get deeper in to the parameters of the entity. Regardless of YAML or automation editor.

Thankful for any tips.

BR

Tobe

Where are you getting this information from?

I’ve never seen anywhere that is printed like that.

Sorry for this, I was really new at HA, still new, but I getting there, still need some help.
There is a already made integration to SMHI (Swedish metrological hydrological institute)
This is an already made integration. I can see the data in my UI.
But when I look at the entity, it only have the states.
-rainy
-cloudy
-sunny
etc etc.
I know the data is in HA, I can see it. but I want to use the temperature, not the state.
The data is coming in from SMHI through an API, that returns a json (I think)
https://opendata.smhi.se/apidocs/

Regardless of the API, the data is already in HA, I can see it in the UI.
I just want to trigger and have conditions based on the temperature, not if it is rainy or not. how to get the data and trigger on it. in the integration page they just refer to the site I refer to above.

This is the integration site

But, this just one case, there are more data I like to get from the web API.

Thanks.

BR
Tobe

I just installed the integration for testing. Here is the entity that was created:

ex

Now, let’s say that I want to use the temperature in an automation. the items listed in the right hand column are called attributes. so, to access those in a template, here is the syntax:

{{ states.weather.smhi_testing.attributes.temperature }}

or better:

{{ state_attr(‘weather.smhi_testing’, ‘temperature’) }}

ex2

1 Like

Hi,

THANKS A LOT!!!
I got it working. This is apoor man aircon I made, actually not a poor man, all aircons are sold out in sweden at the moment. over 30C which is a lot for us vikings.

This is what I did, I bought a pipe fan that fit into my ventilation pip in the bed rum.
The automation is all about turning off and on. I use shelly H&T as a temperature sensor and IKEA trådfri as a switch (because my wife wants to turn things on and off with a button).

So I figure if the room temp is higher than 22C in the room its nice to have a the fan push in some cold air with the fan, but there is no point if the outside temprature is higher than in the room. But later (during night) the outside temperature might drop so need to trigger on that to. For this reason I use both input as both sensor and conditions. I have tested all conditions yet but most of seems to work, most importantly I managed to use the attribute. Later on I will make the trigger and conditions more relative to eachother, but that have to be another day because I have to work now.

Here is my automation.

  • id: ‘1564140501015’
    alias: Sätt på fläkt sovrum1
    trigger:
    • above: ‘22’
      entity_id: sensor.t_sovrum1
      platform: numeric_state
    • below: ‘20’
      entity_id: weather.smhi_home
      platform: numeric_state
      value_template: ‘{{ state.attributes.temperature }}’
      condition:
    • below: ‘20’
      condition: numeric_state
      entity_id: weather.smhi_home
      value_template: ‘{{ state.attributes.temperature }}’
    • above: ‘22’
      condition: numeric_state
      entity_id: sensor.t_sovrum1
      action:
    • data:
      entity_id: switch.flakt_sovrum_2
      service: switch.turn_on

Best Regards
Tobe

I’m glad it’s working for you.

But one oter thing is that when you are posting any code in the forums please ensure that it’s properly formatted.

I’m still learning:-) saw the warning, but was in a hurry and didn’t have the time to fix it. I mostly wanted to thank you.

BR
Tobe

1 Like

Hi here is the 'turn on automation automation again.

- id: '1564140501015'
#turn on fan in bedroom
  alias: Sätt på fläkt sovrum1
  trigger:
#If indoor temp is higher than 22 turn on fan
  - above: '22'
    entity_id: sensor.t_sovrum1
    platform: numeric_state
#If outside temperature is below 24 turn on fan
  - below: '24'
    entity_id: weather.smhi_home
    platform: numeric_state
    value_template: '{{ state.attributes.temperature }}'
  condition:
#Only turn on fan if outside temp is below 24
  - below: '24'
    condition: numeric_state
    entity_id: weather.smhi_home
    value_template: '{{ state.attributes.temperature }}'
#Only turn on fan if indoor temp is above 22
  - above: '22'
    condition: numeric_state
    entity_id: sensor.t_sovrum1

#turn on fan

  action:
  - data:
      entity_id: switch.flakt_sovrum_2
    service: switch.turn_on```

Something buggy here, I did the bast I could 2100 hours Friday night:-)

BR
Tobe

Somehow it was cut in half I try again!


- id: '1564139498966'
#turn off fan in bedroom
  alias: Stäng av fläkt sovrum 1
  trigger:
#If the indoor temperature is below 24C turn off
  - below: '24' 
    entity_id: sensor.t_sovrum1
    platform: numeric_state
# if outdoor temperature is above 23 turn off
  - above: '23' 
    entity_id: weather.smhi_home
    value_template: '{{ state.attributes.temperature }}'
    platform: numeric_state
  condition: []
# turn off fan
  action:
  - data:
      entity_id: switch.flakt_sovrum_2
    service: switch.turn_off

- id: '1564140501015'
#turn on fan in bedroom
  alias: Sätt på fläkt sovrum1
  trigger:
#If indoor temp is higher than 22 turn on fan
  - above: '22'
    entity_id: sensor.t_sovrum1
    platform: numeric_state
#If outside temperature is below 24 turn on fan
  - below: '24'
    entity_id: weather.smhi_home
    platform: numeric_state
    value_template: '{{ state.attributes.temperature }}'
  condition:
#Only turn on fan if outside temp is below 24
  - below: '24'
    condition: numeric_state
    entity_id: weather.smhi_home
    value_template: '{{ state.attributes.temperature }}'
#Only turn on fan if indoor temp is above 22
  - above: '22'
    condition: numeric_state
    entity_id: sensor.t_sovrum1
#turn on fan
  action:
  - data:
      entity_id: switch.flakt_sovrum_2
    entity_id: switch.flakt_sovrum_2
    service: switch.turn_on

Sorry about that.

BR
Tobe

1 Like