My first automation (Warning: Newby Question)

Tags: #<Tag:0x00007f32651447d8> #<Tag:0x00007f3265144698>

New user here and learning about automation. I am attempting to setup a temperature controller, utilising 1-wire temperature sensors and relays. I added several switches that connect to relays via the Rpi GPIO ports (more on this later).

When setting up my first automation I was able to locate the temperature sensors for the trigger and condition sections. However when I started on the actions section I was unable to locate the relays/switches?

I am sure my issue is something really simple, however searching the forum I was unable to find a solution. Please let me know if there is more information required and I will supply it here.

Thanks in advance, and apology for the dumb questions.

Mark

You’ll need to give more information about your set up, but generally physical devices are not connected to the RPi that’s running Home Assistant.

But perhaps I’ve misunderstood.

Hi There and thanks for replying. A discussion on architecture is most welcome as I am new to all this and open to ideas.

The theory behind my setup… I have been using several ESP8266 units running ESPEasy to control aspects of cooling and ventilation for my home data center. I figured adding more functionality would require additional ESP8266 units to be installed, so rather than go down that path I decided to obtain a new Raspberry Pi and consolidate all the functionality on the one computer/controller.

So far I have worked out how to successfully interface the temperature sensors and relays to the Raspberry Pi and Hass, where I can manually read the temperature and activate the relays. My next approach is to introduce some automation to automatically take action based upon particular conditions.

Here is the contents of my configuration.yaml file…

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Relay Control
switch:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      17: FanRelay
      27: DamperRelay
      22: SpareRelay

# Temperature Sensors
sensor:
  - platform: onewire
    names:
      28-02131b13f9aa: Outside_Temp
      28-02131b3fdeaa: Inside_Temp

Here is the content of my first automation…

alias: Temperature Control
description: ''
trigger:
  - type: temperature
    platform: device
    device_id: 7a12af439c0bca30913071e308f79505
    entity_id: sensor.inside_temp_temperature
    domain: sensor
    above: 24
condition:
  - type: is_temperature
    condition: device
    device_id: dfd6d328e77c2a3e882bd09706996bb4
    entity_id: sensor.outside_temp_temperature
    domain: sensor
    below: 22
action: []
mode: restart

Only road block I’ve hit so far has been being able to activate the relays via the automation. Once I have that solved I suspect the rest should be reasonably straight forward. He says, being a total new guy to all this :yum:

Not all physical devices will show up as “devices” in HA. Sometimes (most times…?) they will only show up as entities.

you will find those entities in the dev tools -> states list under “switch.xxx” (xxx = your switch object id).

To use those switches in automations you won’t use a device action, you need to use a service call action that is appropriate for you needs (i.e. switch.turn_on, etc) and then put the switch.xxx entity in for the entity_id.

I don’t use the automation GUI editor but that’s generally how it works.

Hi There finity, thank you so much for the guidance, it worked and I was able to activate the relay based upon the temperatures in the automation.

Silly question… how do I setup a reverse action, so when the temperature in the room drops below 24 the relay closes? Here’s the code that worked…

alias: Temperature Control
description: ''
trigger:
  - type: temperature
    platform: device
    device_id: 7a12af439c0bca30913071e308f79505
    entity_id: sensor.inside_temp_temperature
    domain: sensor
    above: 24
condition:
  - type: is_temperature
    condition: device
    device_id: dfd6d328e77c2a3e882bd09706996bb4
    entity_id: sensor.outside_temp_temperature
    domain: sensor
    below: 22
action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.damperrelay
mode: restart

I am sure the answer is simple… hate asking these dump questions.

Edit: Found the ‘Climate integration’ which appears to be a ready made thermostat which I could use. Only issue, despite my searching and after installing HACS I still have no idea how to install or use the Climate integration?

Thanks, Mark

For some background on what I am trying to achieve… I am attempting to migrate from several ESP8266 NodeMCU units running ESPEasy to a single Rpi running Hass.io. Not sure if anyone here has experience with ESPEasy, but for reference this is the code I created in the ESPEasy ‘rules’ section that controls relays based upon temperature sensors.

On System#Boot do
   notify 1, "%sysname% is started"      // Send email   
   timerset,1,30       // Set timer 1 to 30 seconds
   timerset,2,30       // Set timer 2 to 30 seconds
   timerset,4,30       // Set timer 4 to 30 seconds
   gpio,12,1           // Turn off the fan
   gpio,14,1           // Close the damper
   TaskValueSet 7,1,0  // Set Damper to Close
   TaskValueSet 7,2,0  // Set Fan to Off
   Let,1,22            // Set lower temp to 22
   Let,2,24            // Set upper temp to 24
endon

On Rules#Timer=1 do
   timerset,1,30
   if [Temp1#Temperature] >= [var#2] and [status#Damper]=1
     Event,StartFan
   endif   
   if [Temp1#Temperature] <= [var#1] or [status#Damper]=0
     Event,StopFan 
   endif 
endon

On Rules#Timer=2 do
   timerset,2,30
   if [Temp2#Temperature] < 19 and [counter#Dummy]=0
    Event,OpenDamper
   endif
   if [Temp1#Temperature] >= 25
    Event,CloseDamper
   endif 
endon

On OpenDamper Do
If [status#Damper]=0
 gpio,14,0    // Open the damper
 TaskValueSet 7,1,1
EndIf
EndOn

On CloseDamper Do
If [status#Damper]=1
 gpio,14,1    // Close the damper
 TaskValueSet 7,1,0
EndIf
EndOn

On StartFan Do
If [status#Fan]=0
 gpio,12,0    // Turn on the fan
 TaskValueSet 7,2,1
EndIf
EndOn

On StopFan Do
If [status#Fan]=1
 gpio,12,1    // Turn off the fan
 TaskValueSet 7,2,0
EndIf
EndOn

On ACStatusOn
Let,3,1
EndOn

On Clock#Time=All,3:26 do 
  timerSet,3,55
Endon

on Rules#Timer=3 do
  WifiDisconnect
  Reboot
endon

on Rules#timer=4 do
  Publish %sysname%/IP,%ip%
  Publish %sysname%/Damper/Status,[status#Damper]
  Publish %sysname%/Fan/Status,[status#Fan]
  Publish %sysname%/Door/Status,[StudioDoor#State]
  timerSet,4,30
endon

I am essentially learning the Hass.io automation syntax to try and emulate what I developed above in ESPEasy. Hope this makes sense?

I don’t use the UI editor so I’m not sure how you could do it there in one automation. So the easiest way would be to create another automation to do the opposite.

But if you wrote things by hand you could create a template in the action based on the trigger to set the correct service (turn_on or turn_off).

Hi finity, happy to learn the code side of things… do you have a basic example I might be able to learn from? Thanks, Mark

there are lots of examples in the docs for automations & scripts.

Also there are a ton of examples here on the forum. Just try to look at ones created in the last couple of moths. The basics are the same as the oldest ones but some details have changed with the latest updates to HA.

And the best way to do it is to create an automation with the UI editor and then view it as yaml either in the UI or open it up in a code editor of your choice from the automations.yaml file.

Thanks for the help, I have searched and found a few good examples and will go from there.

Have been attempting to write my first automation, and for some crazy reason it just wont work. I’ve tried using the GUI and writing directly with text editors. Yet everything I’ve tried the automation doesn’t work?

Let’s start with the code…

- id: '1609362739782'
  alias: Open Damper
  description: Open Damper Based on Outside Temperature
  trigger:
  - platform: numeric_state
    entity_id: sensor.outside_temp_temperature
    below: '22'
    above: '0'
  condition:
  - condition: state
    entity_id: binary_sensor.ac_status
    state: 'On'
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.damperrelay
  mode: restart

So when I click on the ‘Execute’ option, the relay turns on… regardless whether the temperature or condition is met or not met? No matter what I set it to, the relay will always turn on when I hit the execute option?

Apology for the dumb question… no doubt the fix will be simple.

If you execute the automation manually the triggers and conditions are ignored.

Groan… I am such an idiot. Back to the drawing board. :roll_eyes:

Do the automations run all the time? If so, how often do they run i.e. every 30 seconds, or are they constantly monitoring the triggers?

Can I assume that when I write an automation and make it active, does that mean the automation is running and waiting for the trigger to occur?

Thank you finity.

as long as the automation is turned on then yes.

Thanks, I am making some progress now. Much appreciated finity.

1 Like