Reef-PI and Home Assistant

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
@sfgabe I have my Reef-PI up and running and am trying to integrate it with Home Assistant. I am not good with the coding but trying to learn. I understand how to create sensors and switches using Reef-PI API and have several working. I would like to set my sunrise/sunset and temperature to reflect a given location to resemble an actual reed the best that I can. I ran across your thread and used your code to get the sunrise/sunset and temperature of Bali. I would like to use the sunrise/sunset times from HA each day to set the sunrise/sunset times in Reef-PI. I would like to do the same with the temperature to control my heater. Is this possible? If so, can you point me in the right direction?
 

nomsmon

Community Member
View Badges
Joined
Sep 7, 2020
Messages
53
Reaction score
35
Location
Northern CA
Rating - 0%
0   0   0
I hadn't heard of Home Assistant; cool project.

What are you trying to control with Home Assistant?

Can it control generic devices over PWM or something?

Is it limited to IoT (probably zigbee and zwave) devices as are shown in the examples?
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
I hadn't heard of Home Assistant; cool project.

What are you trying to control with Home Assistant?

Can it control generic devices over PWM or something?

Is it limited to IoT (probably zigbee and zwave) devices as are shown in the examples?

I am not the best person to say what Home Assistant can and cannot do. I am still learning myself. I use it to control/monitor anything that it can in my house. So far, I have not found anything that cannot be connected either directly or with the use of another device. I have replaced my alarm keypad with a tablet which displays the main dashboard at all times, however, I can also access everything else with a couple presses. I can access all lights/outlets connected, all tvs, thermostats, security cameras, etc.. I also have my office stored and can get an alert at a set time if there is heavy traffic. I have Alexa integrated for voice control of my devices. I can say "Alexa Good Night" and it turns off all lights and sets the alarm. I can say another command which will turn the alarm off. Below is what my dashboard looks like.

hadashboard.JPG


I now have Reef-PI connected and can view anything that I can on Reef-Pi and am now able to control all equipment. I am working on the automations to make things work the way that I want. My plan is to have Home Assistant run Reef-PI macros to do auto water changes and to run an automatic feeder.
 

nomsmon

Community Member
View Badges
Joined
Sep 7, 2020
Messages
53
Reaction score
35
Location
Northern CA
Rating - 0%
0   0   0
I now have Reef-PI connected and can view anything that I can on Reef-Pi and am now able to control all equipment. I am working on the automations to make things work the way that I want. My plan is to have Home Assistant run Reef-PI macros to do auto water changes and to run an automatic feeder.

Interesting, so Home Assistant can control stuff that's directly plugged into the raspberry pi? Is it using the Reef-Pi API to do that or is it just using the raspberry pi directly?
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
I was able to get the heater automation working last night. Home Assistant now receives the temperature in Bali. It then converts it to Fahrenheit. Automation should then send that temperature to Reef-Pi at 4:00 am every day. I manually ran the automation and the temperature in Reef-PI did change so it should be working. I used the same idea for the lights but it is not working. I know part of the issue is the time formatting. Looks like reef-pi wants HH:MM:SS but the time being pulled into Home Assistant for Bali sunrise is H:MM. Anyone know how I can convert this? Also, anyone know how I can add 4 hours to the time? Current sunrise time is 5:00 am and I would like lights to turn on at 9:00 am.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
Interesting, so Home Assistant can control stuff that's directly plugged into the raspberry pi? Is it using the Reef-Pi API to do that or is it just using the raspberry pi directly?
I have Home Assistant running on one Raspberry PI. The only thing directly connected to it is a USB interface to control my alarm system. I have multiple other raspberry pi throughout the house. One is running Reef-PI which has all of my sensors and equipment connected to it. I am able to access it to control/monitor via API. Google "reef-pi api" and it will show you everything that can be done with API. I also have 3 terrariums being monitored the same way but not with Reef-PI.
 

jnvd3b

Active Member
View Badges
Joined
Dec 21, 2017
Messages
108
Reaction score
101
Rating - 0%
0   0   0
I have used HA for roughly 4 years.
If you want to offset the time for your automation it can be done.

My question for the lights is how is reefpi controlling your lights. Might be easier to just keep the lights directly controlled by HA. That is how I am doing mine via an LED driver connected to esphome/nodemcu board.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
I have used HA for roughly 4 years.
If you want to offset the time for your automation it can be done.

My question for the lights is how is reefpi controlling your lights. Might be easier to just keep the lights directly controlled by HA. That is how I am doing mine via an LED driver connected to esphome/nodemcu board.
I currently have reef-pi on auto Diurnal to ramp up each channel and then ramp down. I would like to keep reef-pi controlling the lights in case there is a problem with Home Assistant or my wifi. If controlled fully by Home Assistant, if there is a failure of either Home Assistant or my network, the lights would not turn on.
 

jnvd3b

Active Member
View Badges
Joined
Dec 21, 2017
Messages
108
Reaction score
101
Rating - 0%
0   0   0
I currently have reef-pi on auto Diurnal to ramp up each channel and then ramp down. I would like to keep reef-pi controlling the lights in case there is a problem with Home Assistant or my wifi. If controlled fully by Home Assistant, if there is a failure of either Home Assistant or my network, the lights would not turn on.

can you send the automation that you are using to presumably send reefpi a command to set the light schedule?
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
can you send the automation that you are using to presumably send reefpi a command to set the light schedule?

I have the following set as a switch to test using the unadjusted time received:

Code:
  - platform: rest
    name: Reef Lights Sunrise/Sunset CH1
    resource: http://<MYIP>:8089/api/lights/1
    method: POST
    username: !secret reefpi_username
    password: !secret reefpi_password
    body_on: '{"id":"1","name":"Light 1","channels":{"0":{"name":"Intensity","on":true,"min":0,"max":100,"pin":0,"color":"#006eff","manual":false,"value":0,"profile":{"name":"","type":"diurnal","config":{"start":{{ states.sensor.reefsunrisebali.state }},"end":{{ states.sensor.reefsunsetbali.state }}},"min":0,"max":0}},"1":{"name":"Spectrum","on":true,"min":0,"max":100,"pin":1,"color":"","manual":false,"value":0,"profile":{"name":"","type":"fixed","config":{"start":"00:00:00","end":"23:59:59","value":0},"min":0,"max":0}}},"jack":"3","enable":true}'
    body_off: '{"id":"1","name":"Light 1","channels":{"0":{"name":"Intensity","on":true,"min":0,"max":100,"pin":0,"color":"#006eff","manual":false,"value":0,"profile":{"name":"","type":"diurnal","config":{"start":{{ states.sensor.reefsunrisebali.state }},"end":{{ states.sensor.reefsunsetbali.state }}},"min":0,"max":0}},"1":{"name":"Spectrum","on":true,"min":0,"max":100,"pin":1,"color":"","manual":false,"value":0,"profile":{"name":"","type":"fixed","config":{"start":"00:00:00","end":"23:59:59","value":0},"min":0,"max":0}}},"jack":"3","enable":true}'
    is_on_template: '{{ value_json.on }}'
    headers:
        Connection: keep-alive
        content-type: application/json
        Referer: http://<MYIP>/
        Cookie: !secret reefpi_cookie

Then run this automation:

Code:
- id: '1600749263620'
  alias: Reef Light Sunrise/Sunset Adjustment
  description: ''
  trigger:
  - at: 04:00:00
    platform: time
  condition: []
  action:
  - data: {}
    entity_id: switch.reef_lights_sunrise_sunset_ch1
    service: switch.turn_on

I'm running the same thing for the heater except the body_on and body_off information is different. I also do not have the method defined in my heater but tried it here when it didn't work.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
What integration are you using for the sensor.reefsunrisebali

sun?


Code:
  - platform: scrape
    resource: https://tides4fishing.com/as/west-indonesia/banjuwangi-bali-str
    select: "#amanecer_anochecer_datos_salida_sol div.amanecer_anochecer_datos_salida_puesta_sol2"
    name: ReefSunriseBali
    scan_interval: 7200
    value_template: '{{ (value.split(" h")[0]) }}'

This pulls in the sunrise and I have one for the sunset as well. For today it shows sunrise at 5:11 and sunset at 17:18. Looks like reefpi wants 05:11:00 and 17:18:00.
 

jnvd3b

Active Member
View Badges
Joined
Dec 21, 2017
Messages
108
Reaction score
101
Rating - 0%
0   0   0
I wish I was better with templating. IMO you need a new template sensor or revise the value_template of your scrape sensor somehow to get into the format you need for reefpi.

I attempted this and got one result that showed 5:11:00 (in the template developer tools section) but it did not work correctly when trying to add it as a template sensor.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
I wish I was better with templating. IMO you need a new template sensor or revise the value_template of your scrape sensor somehow to get into the format you need for reefpi.

I attempted this and got one result that showed 5:11:00 (in the template developer tools section) but it did not work correctly when trying to add it as a template sensor.

Thanks. I will play with that. I know it works because I pulled this from sfgabe's github but he also used a rest_command which is not in his github filed so I dont know how it may have altered things.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
I wish I was better with templating. IMO you need a new template sensor or revise the value_template of your scrape sensor somehow to get into the format you need for reefpi.

I attempted this and got one result that showed 5:11:00 (in the template developer tools section) but it did not work correctly when trying to add it as a template sensor.

What did you use that got that result for you?
 

jnvd3b

Active Member
View Badges
Joined
Dec 21, 2017
Messages
108
Reaction score
101
Rating - 0%
0   0   0
1600912281543.png


I was just looking through templating examples on the forums and this one sort of worked.
What was nice is it allowed an offset since the " - strptime('4', '%H') " portion was simply subtracting 4 hours. But you want to add 4 hours so I am lost again on how to do that.

I would say posting on the HA forum and asking for help formatting " 5:11" to "09:11:00" via a template would be your best bet.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
1600912281543.png


I was just looking through templating examples on the forums and this one sort of worked.
What was nice is it allowed an offset since the " - strptime('4', '%H') " portion was simply subtracting 4 hours. But you want to add 4 hours so I am lost again on how to do that.

I would say posting on the HA forum and asking for help formatting " 5:11" to "09:11:00" via a template would be your best bet.
Thanks. I was going to go to HA forum if no one here knew. I was hoping sfgabe would be around to possibly give some direction. I will play around with your template idea and see what i can get from it. This will help me learn more about HA as well.
 
OP
OP
O

overmyhead

Community Member
View Badges
Joined
Sep 22, 2020
Messages
26
Reaction score
29
Location
GA
Rating - 0%
0   0   0
With a lot of help from the Home Assistant community, I was finally able to get this working. Below is the template used to convert the time to the correct format and add 4 hours to adjust to when I want the lights on.

Code:
{% set h, m = value.strip().split(':') %}
{% set h, m = [ h, m[:2] ] | map('int') %}
{% set t = now().replace(hour=h, minute=m, second=0).timestamp() + 4 * 60 * 60 %}
{{ t | timestamp_custom('%H:%M:%S') }}

Now I am getting the sunrise/sunset times for Bali and updating Reef-Pi every morning at 4:00 am. I am also receiving the current water temperature in Bali and adjusting Reef-PI at 4:00 am as well, however, I plan to refresh it more often to reflect changes multiple times throughout the day.
 

jnvd3b

Active Member
View Badges
Joined
Dec 21, 2017
Messages
108
Reaction score
101
Rating - 0%
0   0   0
With a lot of help from the Home Assistant community, I was finally able to get this working. Below is the template used to convert the time to the correct format and add 4 hours to adjust to when I want the lights on.

Code:
{% set h, m = value.strip().split(':') %}
{% set h, m = [ h, m[:2] ] | map('int') %}
{% set t = now().replace(hour=h, minute=m, second=0).timestamp() + 4 * 60 * 60 %}
{{ t | timestamp_custom('%H:%M:%S') }}

Now I am getting the sunrise/sunset times for Bali and updating Reef-Pi every morning at 4:00 am. I am also receiving the current water temperature in Bali and adjusting Reef-PI at 4:00 am as well, however, I plan to refresh it more often to reflect changes multiple times throughout the day.

Thank you for sharing a working solution. HA forums have a lot of good people just like R2R forums, and I knew it could be done I just didn't know how. I actually copied the above and got it working in my instance as well, might use this down the road.

Funny enough HA actually got me back into reefkeeping 3ish years ago, there was a long thread where someone was using HA exclusively to control multiple tanks. I decided shortly thereafter the reliability needed with a controller wasn't going to allow me to use HA (though it can be done) and I think what you have (both reefpi and HA) is a happy medium for both reliability and 'extras'

worst case scenario if your HA instance fails, automation doesn't run, etc is the sunrise/sunset stays the same as the day prior right?
 

Being sticky and staying connected: Have you used any reef-safe glue?

  • I have used reef safe glue.

    Votes: 94 87.9%
  • I haven’t used reef safe glue, but plan to in the future.

    Votes: 6 5.6%
  • I have no interest in using reef safe glue.

    Votes: 4 3.7%
  • Other.

    Votes: 3 2.8%
Back
Top