Home Assistant integration

Iranian45

Community Member
View Badges
Joined
Dec 12, 2018
Messages
39
Reaction score
46
Rating - 0%
0   0   0
Hi All,

I am trying to integrate my reef-pi into my new home assistant setup. I only use it currently for turning on/off lights and pumps. can someone help me get this added? I have seen this github.com/sfgabe/home_assistant but am unsure of what to put in the body_on: body_off: and is_on_template: sections as well as what to put in the !secret reefcontrolpi_cookie section.

thanks for any help.
 

sfgabe

Active Member
View Badges
Joined
Sep 7, 2018
Messages
167
Reaction score
264
Rating - 0%
0   0   0
Hi All,

I am trying to integrate my reef-pi into my new home assistant setup. I only use it currently for turning on/off lights and pumps. can someone help me get this added? I have seen this github.com/sfgabe/home_assistant but am unsure of what to put in the body_on: body_off: and is_on_template: sections as well as what to put in the !secret reefcontrolpi_cookie section.

thanks for any help.
Welcome @Iranian45 !

Firstly, the !secret reefcontrolpi_cookie is going to be the full string of the cookie (you can get this though chrome "inspect" or any of the other many cookie viewers. It will look like "AUTH=123456...=" You may need to reset this every so often, especially if you update your home assistant installation frequently.

Everything else happens through the Reef-Pi API and the HomeAssistant Rest Sensor. For instance, you can get information about your reef-pi build with this in sensors.yaml:

Code:
- platform: rest
  name: ReefControlPiSysUptime
  username: !secret reefcontrolpi_username
  password: !secret reefcontrolpi_password
  authentication: basic
  json_attributes:
    - name
    - ip
    - uptime
    - cpu_temperature
    - version
  resource: http://reefcontrolpi.local/api/info
  headers:
      Connection: keep-alive
      content-type: application/json
      Referer: http://reefcontrolpi.local/
      Cookie: !secret reefcontrolpi_cookie

To actually control some of the reef-pi switches, etc. you can send the full command through a Home Assistant rest switch template. Here is how I can turn on a specific light setting with this as a switch:

Code:
- platform: rest
  name: Kessil Light Level 1
  resource: http://reefcontrolpi.local/api/lights/1
  username: !secret reefcontrolpi_username
  password: !secret reefcontrolpi_password
  body_on: '{"id":"1","name":"Kessil","channels":{"0":{"name":"Color","min":1,"start_min":10,"max":99,"reverse":true,"pin":0,"color":"","profile":{"type":"fixed","config":{"value":1}}},"1":{"name":"Brightness","min":1,"start_min":10,"max":99,"reverse":true,"pin":1,"color":"","profile":{"type":"fixed","config":{"value":10}}}},"jack":"1"}'
  body_off: '{"id":"1","name":"Kessil","channels":{"0":{"name":"Color","min":1,"start_min":10,"max":99,"reverse":true,"pin":0,"color":"","profile":{"type":"fixed","config":{"value":1}}},"1":{"name":"Brightness","min":1,"start_min":10,"max":90,"reverse":true,"pin":1,"color":"","profile":{"type":"fixed","config":{"value":1}}}},"jack":"1"}'
  is_on_template: '{{ value_json.channels["1"].profile.config.value == 10 }}'
  headers:
      Connection: keep-alive
      content-type: application/json
      Referer: http://reefcontrolpi.local/
      Cookie: !secret reefcontrolpi_cookie

It looks overwhelming but it's just a copy and paste from what you see when you set your desired setting and look at the api return. So in the above example, I've gone to Reef-Pi and set my Kessil Lights to a brightness of 10, then I went to "http://reefcontrolpi.local/api/lights/1" I copy all the output and that is my body_on call. Then do the same for whatever I want to be body_off.

The is_on_template can just cherry pick whichever parameter is really signaling the change as the indicator, but sending the full api call in the on / off setting will be more reliable because you don't end up with a mix and match if you're flipping switches on and off.
 
Last edited:
OP
OP
Iranian45

Iranian45

Community Member
View Badges
Joined
Dec 12, 2018
Messages
39
Reaction score
46
Rating - 0%
0   0   0
@sfgabe thank you so much for this. I am going to check it out this weekend. I actually started having issues tonight with reef-pi (i think its the wiring but havent had a chance to diagnose it yet). So once i get it up and running again, I will try to integrate it with HA again.
 

sfgabe

Active Member
View Badges
Joined
Sep 7, 2018
Messages
167
Reaction score
264
Rating - 0%
0   0   0
Also I should say that I am super paranoid about turning on anything like refill or ato pumps through home assistant in case of mid-way communication failure on either side and a pump not being shut off correctly. For things like that I actually set the reef-pi schedule through the API call and let it function locally.

So for an ATO instead of doing:
Home Assistant trigger at 08:00 --> turn on
Home Assistant trigger at 08:05 --> turn off
(if Home Assistant goes down or the wifi goes out in this 5 minutes, my tank is overflowing)

it's doing:
Home Assistant trigger at 07:55 --> schedule pump on at 08:00, set run time for 5 minutes
Home Assistant trigger at 08:10 --> clear schedule
(if Home Assistant goes down anywhere here it doesn't matter, it will either not run at all or run for another 5 minutes the next day on the same schedule)
 
Last edited:
OP
OP
Iranian45

Iranian45

Community Member
View Badges
Joined
Dec 12, 2018
Messages
39
Reaction score
46
Rating - 0%
0   0   0
Also I should say that I am super paranoid about turning on anything like refill or ato pumps through home assistant in case of mid-way communication failure on either side and a pump not being shut off correctly. For things like that I actually set the reef-pi schedule through the API call and let it function locally.

So for an ATO instead of doing:
Home Assistant trigger at 08:00 --> turn on
Home Assistant trigger at 08:05 --> turn off
(if Home Assistant goes down or the wifi goes out in this 5 minutes, my tank is overflowing)

it's doing:
Home Assistant trigger at 07:55 --> schedule pump on at 08:00, set run time for 5 minutes
Home Assistant trigger at 08:10 --> clear schedule
(if Home Assistant goes down anywhere here it doesn't matter, it will either not run at all or run for another 5 minutes the next day on the same schedule)

At this time I am more interested in monitoring the reefpi through the HA dashboard then anything. I have had reefpi set up for some time so controlling through HA isnt that important yet.
 
OP
OP
Iranian45

Iranian45

Community Member
View Badges
Joined
Dec 12, 2018
Messages
39
Reaction score
46
Rating - 0%
0   0   0
@sfgabe Hey could you look at my sensors and switches and see why i cant find them in HA once I restart? Just for some context, all I am trying to do right now is view the status of the outlets through HA.


i just checked the logs too and I am getting this error:

Log Details (ERROR)
Mon Oct 14 2019 14:50:15 GMT-0400 (Eastern Daylight Time)
Error fetching data: <PreparedRequest [GET]> from http://http//biocube29.local/api/info failed with HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //biocube29.local/api/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6c4dc690>: Failed to establish a new connection: [Errno -3] Try again'))


and

Log Details (ERROR)
Mon Oct 14 2019 14:48:28 GMT-0400 (Eastern Daylight Time)
No route to resource/endpoint: http://biocube29.local/api/equipment/1
 

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,843
Reaction score
17,058
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
@sfgabe Hey could you look at my sensors and switches and see why i cant find them in HA once I restart? Just for some context, all I am trying to do right now is view the status of the outlets through HA.


i just checked the logs too and I am getting this error:

Log Details (ERROR)
Mon Oct 14 2019 14:50:15 GMT-0400 (Eastern Daylight Time)
Error fetching data: <PreparedRequest [GET]> from http://http//biocube29.local/api/info failed with HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //biocube29.local/api/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6c4dc690>: Failed to establish a new connection: [Errno -3] Try again'))


and

Log Details (ERROR)
Mon Oct 14 2019 14:48:28 GMT-0400 (Eastern Daylight Time)
No route to resource/endpoint: http://biocube29.local/api/equipment/1
you have double http in the address. Remove one http from config value: "from http://http//biocube29.local/api/info"


Disclaimer, i have not used home assistant, this is just from observing the logs you shared.
 
OP
OP
Iranian45

Iranian45

Community Member
View Badges
Joined
Dec 12, 2018
Messages
39
Reaction score
46
Rating - 0%
0   0   0
you have double http in the address. Remove one http from config value: "from http://http//biocube29.local/api/info"


Disclaimer, i have not used home assistant, this is just from observing the logs you shared.

Thank you I have corrected that but it did not fix my issue.

Error fetching data: <PreparedRequest [GET]> from http://biocube29.local/api/info failed with HTTPConnectionPool(host='biocube29.local', port=80): Max retries exceeded with url: /api/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x724544d0>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
 

sfgabe

Active Member
View Badges
Joined
Sep 7, 2018
Messages
167
Reaction score
264
Rating - 0%
0   0   0
Thank you I have corrected that but it did not fix my issue.

Error fetching data: <PreparedRequest [GET]> from http://biocube29.local/api/info failed with HTTPConnectionPool(host='biocube29.local', port=80): Max retries exceeded with url: /api/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x724544d0>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

That just looks like a connection error. Some things to try
  • confirm the http://biocube29.local/api/info address works as-is, some of the api addresses have changed depending on which version of reef-pi you're using
  • https://biocube29.local/api/info
  • http://biocube29/api/info - depending on my router setting sometimes it doesn't use the ".local"
  • https://biocube29/api/info
  • check the port - I don't remember if the default setup is on port 80 but it may be something else
  • make sure you've got the right cookie and format "AUTH=1234etc="
  • try using an incognito tab to retrieve the cookie, or closing all the reef-pi tabs and clearing the cache and getting the cookie again, sometimes I think it may have issues if the cookie is used in more than one place at the same time
 

sfgabe

Active Member
View Badges
Joined
Sep 7, 2018
Messages
167
Reaction score
264
Rating - 0%
0   0   0
Just looked at the YAML, that looks fine - make sure both the "referrer" and "resource" http typo is fixed, and that you have the right username and password in the secret file along with the cookie. 99% of the time I've had issues I just need to reset the cookie or remember that I changed the password. Are the other sensors and switch working?
 

High pressure shells: Do you look for signs of stress in the invertebrates in your reef tank?

  • I regularly look for signs of invertebrate stress in my reef tank.

    Votes: 35 31.3%
  • I occasionally look for signs of invertebrate stress in my reef tank.

    Votes: 26 23.2%
  • I rarely look for signs of invertebrate stress in my reef tank.

    Votes: 21 18.8%
  • I never look for signs of invertebrate stress in my reef tank.

    Votes: 30 26.8%
  • Other.

    Votes: 0 0.0%
Back
Top