Act upon sensor reading (newbie question)

Hi guys, first post here, struggling to make something work :slight_smile:

I have four sonoffs basic with tasmota 6.4.1, to one of them I wired a DHT22 temp/hum sensor and configured it properly

The sensors are read via MQTT and they show the telemetry values properly in HA overview screen, then after reading a lot of examples here and googling around I defined this simple automation to turn on or off one of them based on the humidity reading.

it does nothing :slight_smile:

here are the sensor definitions and the automation as I have them in configuration.yaml

to test the automation I send MQTT messages changing the humidity value, of course its updated inmediatelly in the sensor reading in the overview screen

can you guys slap me to the correct path? Thanks!!

## 01:19:44 RSL: tele/sonoff/SENSOR = {"Time":"2019-03-03T01:19:44","AM2301":{"Temperature":28.2,"Humidity":42.5},"TempUnit":"C"}

sensor Temperatura:
  platform: mqtt
  state_topic: 'tele/sonoff/SENSOR'
  name: 'Temperatura'
  value_template: '{{ value_json["AM2301"]["Temperature"] }}'
  unit_of_measurement: 'Ā°C'


sensor Humedad:
  platform: mqtt
  state_topic: 'tele/sonoff/SENSOR'
  name: 'Humedad'
  value_template: '{{ value_json["AM2301"]["Humidity"] }}'
  unit_of_measurement: '%'



automation:
- alias: 'Anafe prendido'
  trigger:
    platform: numeric_state
    entity_id: sensor.humedad
    above: 70

  action:
    service: homeassistant.turn_on
    entity_id: switch.sonoff_3

- alias: 'Anafe apagado'
  trigger:
    platform: numeric_state
    entity_id: sensor.humedad
    below: 60

  action:
    service: homeassistant.turn_off
    entity_id: switch.sonoff_3

you need to turn the automation ā€˜onā€™. There are a couple of ways to do that.

One way is, if you always want the automation to be enabled at start up of HA no matter what the previous state was prior to shutdown, then add ā€œinitial_state: trueā€ to the automation.

If you always want it to be restored to itā€™s prior state at start up then you need to go to the ā€œdev-statesā€ page (left menu, bottom, <> icon) then find the automation in the list, click the box to the left of the automation then turn on the toggle in the box that pops up.

Thanks for the reply, I added that to the automations,

[edit] it seems to work, its a work in progress!

now I have another related question, now that I have the whole set of automations to control this stage, is it possible to group them so I can enable all of them at once if I want to automate this stage?

I need to make another stage with a different set of automations controlling the same switches

what I mean, this is a whole set or stage of automation, I want to be able to enable or disable this set as a group. Then I want to create a new group that controls the same device and switches but using different triggers and be able to enable or disable these too as a group.

this one is the group I just finished:

- id: '1551649140920'
  alias: Anafe Prendido
  initial_state: true
  trigger:
  - above: '70'
    entity_id: sensor.humedad
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_on
    entity_id: switch.Anafe

- id: '1551649140921'
  alias: Anafe Apagado
  initial_state: true
  trigger:
  - below: '60'
    entity_id: sensor.humedad
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_off
    entity_id: switch.Anafe

- id: '1551649450423'
  alias: Escenario 1
  initial_state: true
  trigger:
  - above: '18'
    entity_id: sensor.temperatura
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_on
    entity_id: switch.Heladera

- id: '1551649450424'
  alias: Escenario 2
  initial_state: true
  trigger:
  - above: '75'
    entity_id: sensor.humedad
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_on
    entity_id: switch.Heladera

- id: '1551649450425'
  alias: Escenario 3
  initial_state: true
  trigger:
  - below: '15'
    entity_id: sensor.temperatura
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_off
    entity_id: switch.Heladera

- id: '1551649963238'
  alias: Escenario 4
  initial_state: true
  trigger:
  - below: '50'
    entity_id: sensor.humedad
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_on
    entity_id: switch.Ventilador
    
- id: '1551649963239'
  alias: Escenario 5
  initial_state: true
  trigger:
  - above: '65'
    entity_id: sensor.humedad
    platform: numeric_state
  condition: []
  action:
    service: homeassistant.turn_off
    entity_id: switch.Ventilador

you can do it two ways (sounds familiar doesnā€™t it :wink:) -

one way is to create a group in HA that includes the automations you want to have together. then just turn on & off the group.

A better way (the way I do it) is to create an entity card in lovelace and list all of those automations there. then you can either turn them on/off individually or use the group toggle to control them all at once.

1 Like

Keep in mind that yesterday I knew nothing about HA be gentle LOL

Do you have examples of what you just told me? I googled for group examples before asking but found no one to derive from.

What makes me happy is that I just made a table of truth of all of the conditions and all work as expected!!! could not be happier !

Thanks, I donā€™t know how to add and automation to it, tried this:

default view:
    name: "Pantalla de control"
    view: yes
    entities:
    -id: '1551649140920'

The id is one of the automations, but this errors when I check the config.

Managed to add a new tab which has a toggle that is supposed to turn all on or off, but this is not the case, if I want to turn off all the automations in the view I had to switch them individually:

  automation_view:
    view: yes
    name: Automation
    entities:
      - automation.Anafe_Apagado
      - automation.Anafe_Prendido
      - automation.Escenario_1
      - automation.Escenario_2
      - automation.Escenario_3
      - automation.Escenario_4
      - automation.Escenario_5

I guess I was wrong that the toggle operated automations. I tried it on mine and apparently it doesnā€™t.

Sorry about that.

And thinking outside the box, do you have an idea on how to do what Iā€™m trying to accomplish? I mean have different set of automations? Maybe be able to toggle these groups instead of each an every one of their components.

Iā€™m not sure I follow why you would want to enable or disable the automations so often you would need an automation to do it. Usually the automation is turned on or off and left that way. I do have a few automations that I want to delay turning on but that is generally the exception rather than the rule.

Oh, let me explain, maybe Iā€™m doing it the wrong wayā€¦

Iā€™m trying to automate a fridge for charcuterie.

There are three ā€œprogramsā€ each one with different triggers operating form the input of the same temp/humidity sensor, so for example, you need to run the first program for 5 days, then next one for a month and the third program is a different use of the same fridge also with other trigger points.

So, I donā€™t want to automate everything, I just want to switch from program1 (and its whole set of automations) to program2 or program3, I do this myself no problem and I keep track of days, I just donā€™t want to fiddle with configs every time I need to switch programs.

What I posted earlier is the automation of one of the programs.

you can automate automations being enabled or disabled by using the service ā€œautomation.turn_onā€ or ā€œautomation.turn_offā€ in the action section of another automation. I think you will have to list all of the entity_idā€™s of the automations you want the service to act on:

action:
  service: automation.turn_on
  entity_id:
    - automation.automation_1
    - automation.automation_2
    - automation.automation_1
    etc

Tried this, did not work:

input_select:
  heladera:
    name: Heladera
    options:
      - Estufado de fiambres
      - Estacionado de fiambres
      - Madurado de carnes
      - None
    initial: Estufado de fiambres

- id: '1551666751805'
  alias: Activar Estacionado
  trigger:
  - entity_id: input_select.heladera
    platform: state
    to: Estufado de fiambres
  condition: []
  action:
  - service: automation.turn_on
      entity_id:
      - automation.Anafe_Apagado
      - automation.Anafe_Prendido
      - automation.Escenario_1
      - automation.Escenario_2
      - automation.Escenario_3
      - automation.Escenario_4
      - automation.Escenario_5

What about it didnā€™t work? What did it not do that you were expecting it to do?

The same as before :grinning: but it didnā€™t work, will open a new thread as the title of this one does not correlate to my current question.

I got to think that a fridge is in essence an a/c unit or heater so Iā€™m replacing the automations with a bunch of climate generic thermostat, being creative with the values allows me to do the same in a much simpler way without a single automation, this would allow, for example, to group things better :slight_smile:

Thanks a ton!!