søndag 10. november 2019

My first time in Node-RED, motion sensor automation

I have heard about Node-RED several times. But until now I tried to do everything in Home Assistant and yaml.

Today I decided to try it out, I watched a couple of youtube videos and decided to try it out with a motion sensor and a light.

I only want it to turn on if we're home, and if the sun is down. And then to turn off when there's no motion detected.

Below is a picture of the flow. The names are in norwegian. So I'll explain.



First box is a state node of the motion sensor wich is connected to a switch.
The switch have two outputs on and off. If on is detected it goes through the "ute?" and "borte" which checks the current state of two input boolean switches I made. One for out and one for away. If one of those are on the flow stops. If not it goes on to the "Sol nede?" which checks if the sun is below the horizon.
If it's not below the horizon the flow stops. If it is it continues to "Lys av?" which checks if the light is off. If the light is off it turns it on. If not the flow stops.

If the motion detector goes to off, it turns the light off "Slå av lys"

A bit hard to explain only in words. But I hope you get the Idea.

onsdag 6. november 2019

Add Roborock S5 and create an easy automation for daily cleaning

I did buy a Roborock S5. Wifey was happy for this. 
Thw first I had to do was of course to set it up in Home Assistant

To do this you first have to find the token of the vacuum. I've got an android-phone so I did it like this:

First downloaded an earlier version of the Mi Home app: https://www.apkmirror.com/apk/xiaomi-inc/mihome/mihome-5-4-49-release/

I have to use that older version because the newer versions donesn't save the token in the log file.

Installed the app and connected the Roborock, then opened the log-file which is found in the smarthome/logs folder on the phone and searched for "token", then added the following lines in configuration.yaml:


vacuum:
  - platform: xiaomi_miio
    host: 192.168.1.108
    token: *******************
    name: Gudrun

I also reserved the dhcp in my router. So that the vacuum will get the same ip-adress every time the router reboots.

Then I created the automation for daily cleaning:


- id: '1568470324361'
  alias: Støvsuge
  trigger:
  - at: '10:00:00'
    platform: time
  condition: []
  action:
  - data:
      entity_id: vacuum.gudrun
    service: vacuum.start
  initial_state: 'true'

I will later add a condition that if we're on a vacation the automation will not run.

onsdag 16. januar 2019

Moving Hass.io from Raspberry Pi to computer

Hass.io has started to slow down abit on the raspberry. Long boot-times too. So I decided to move the install to an Asus VivoPC that I haven't been using for a while, still a pretty small piece and running silent.

I just moved the files from config-directory and everything was working.

This is the steps I did:

First downloaded Ubuntu server iso-file. https://www.ubuntu.com/download/server

And Rufus to make a bootable USB. https://rufus.ie/

Installed Ubuntu server on the PC. Then SSH'd into it from my Computer and ran the script from Hasscasts by running this command: 
sudo curl  -sL https://raw.githubusercontent.com/hasscasts/hass.io-01/master/install.sh | bash -


After that I moved the config files and everything is running smooth.

Youtubevideo showing the steps:





torsdag 13. desember 2018

Make bathroom fan start and stop automatically when showering.

I have a bathroom fan that I want to start automatically when the shower turns on and the humidity rises. Then to automatically turn off again when the humidity level has fallen again. After some googling, asking and testing then trial and error, I found out after several days that the following setup works.

First I create two new binary trend sensors based on the humidity sensor I got on the bathroom.

This is the sensors written in the configuration.yaml file:

binary_sensor:
 - platform: trend
   sensors:
      bad_fukt_rising:
        entity_id: sensor.bad_inne_fukt_humidity
        min_gradient: 0.008
        max_samples: 4
       
        
      bad_fukt_falling:
        entity_id: sensor.bad_inne_fukt_humidity
        min_gradient: -0.004
        max_samples: 10

The first one turns on when the humidity is rising, I found out that I had to set the "max_samples" values. before I entered anything in the rising sensor it sometimes turned on when it shouldn't

And before I entered the value in the falling sensor It stopped earlier than I wanted it too.


The sensors dont do anything on their own.. So i had to make some automations too.

This is what I have in the automations.yaml file:

  - alias: 'Badevifte auto on'
    trigger:
      - platform: state
        entity_id: binary_sensor.bad_fukt_rising
        from: 'off'
        to: 'on'
    action:
        service: switch.turn_on
        entity_id: switch.bad_oppe_vifte

  - alias: 'Badevifte auto off'
    trigger:
      platform: state
      entity_id: binary_sensor.bad_fukt_falling
      from: 'on'
      to: 'off'
    action:
        service: switch.turn_off
        entity_id: switch.bad_oppe_vifte

This is what happens, when the shower is turned on the humidity is rising. This turn the rising sensor on, which then triggers the auto on automation. Then when the humidity stop rising, and the rising sensor turns off, nothing happens, because that is not set to trigger anything.

When the humidity starts to fall the falling sensor turns on. This stays on until the humidity stops falling, then triggers the auto off automation when the sensor goes to state "off"

It might need some more tweaking and so. But so far this is working good.


fredag 30. november 2018

My first script in home assistant

The first post here. And my first script in Home Assistant. I have installed Mopidy and Snapcast on my server and have a couple of orange pi's to run snapcastclient to get multiroom audio.

On the bathroom I have this orange pi with a 433mhz plug switch connected to the Aux in on my Pinell Supersound II Radio. I want to have a switch on the Home Assistant UI to turn the orange pi and pinell on and select the right source on the radio.

Some googling and trial and error.. I found that this is working:

I have this in the scripts.yaml file:

musikk_bad_on:

    alias: musikk bad on
    sequence:
      - service: media_player.turn_on
        entity_id:
          - media_player.pinell_supersound_002261086da2
      - service: switch.turn_on
        entity_id:
          - switch.musikk_bad_switch
      - service: media_player.select_source
        data:
           entity_id: media_player.pinell_supersound_002261086da2
           source: 'AUX inngang'

musikk_bad_off:
         
    alias: musikk bad off
    sequence:
      - service: media_player.turn_off
        entity_id:
         - media_player.pinell_supersound_002261086da2
      - service: switch.turn_off
        entity_id:
          - switch.musikk_bad_switch

And I did put this under switch in my configuration.yaml file.

  - platform: template
    switches:
      musikkbad:
        friendly_name: "Musikk bad"
        value_template: "{{ is_state('switch.musikk_bad_switch', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.musikk_bad_on
        turn_off:
          service: script.turn_on
          entity_id: script.musikk_bad_off