Need help setting up OctoPrint with HA

I’m trying to get my OctoPrint server included in my HA setup.

OctoPrint setup:

OctoPrint Version 1.3.2 (master branch)
on a RPi 2 over wifi (192.68.0.30 and standard port 80)

HA setup:

HA Version 0;41.0 (believe is latest)
on RPi 3 over wifi

When I add OctoPrint to the configuration.yaml like this

# Octoprint Server
octoprint:
    host: 192.68.0.30
    api_key: (removed)

I get the config error on the HA main page, and then the error in the home-assistant.log gives this:

> 17-04-02 07:44:53 WARNING (MainThread) [homeassistant.setup] Setup of octoprint is taking over 10 seconds.
> 17-04-02 07:45:13 ERROR (Thread-12) [homeassistant.components.octoprint] Failed to update OctoPrint status.  Error: HTTPConnectionPool(host='192.68.0.30', port=80): Max retries exceeded with url: /api/printer (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x71cc1a50>, 'Connection to 192.68.0.30 timed out. (connect timeout=30)'))
> 17-04-02 07:45:13 ERROR (Thread-12) [homeassistant.components.octoprint] Error setting up OctoPrint API: ConnectTimeout(MaxRetryError("HTTPConnectionPool(host='192.68.0.30', port=80): Max retries exceeded with url: /api/printer (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x71cc1a50>, 'Connection to 192.68.0.30 timed out. (connect timeout=30)'))",),)
> 17-04-02 07:45:13 ERROR (MainThread) [homeassistant.setup] Setup failed for octoprint: Component failed to initialize.

My OctoPrint connection looks this

I’m not sure what i’m missing, and could use some help.

Hey there, I’ve got Octoprint added to HA, with the same versions you do.
Couple of things… Do you have the API “enabled” in Octoprint/settings/API?

Just noticed above, your IP address is: 192.68.0.30
That can’t be right, typo?

Also, using a program like lynx, or links, are you able to get to the octoprint webpage from the HA server? eg: links http://192.168.0.30

@xstrex - you are absolutely correct. I didn’t even notice, but my IP address was wrong. can’t believe I missed that. I must have looked it over 5 times. Guess each time I convinced myself it was correct.

Once I corrected to 192.168.0.30 it worked fine.

thank you very much for pointing me in correct direction!

@xstrex - thanks again. It’s looking good - i’ve got the sensors in, grouped how I want to see.

Do you know how to switch the temperature reading into deg C though? That’s how I’m used to seeing in OctoPrint and on the machine.

Create a template sensor. There is even an example on the below webpage for another conversion of measurement, but pretty sure you’ll be able to use that as a starting point.

And in case you were gonna look for it, this is the formula : T(°C) = (T(°F) - 32) × 5/9

@IROTRAS No problem man, done something similar myself. Glad it’s finally showing up!

Now ya just have to hook a camera up! With that, and the above sensor data, you can check your prints from anywhere. It works great!

thanks @farstreet ! ill look at that later tonight. ive been meaning to understand more about the template sensor functionality

@xstrex i have been trying to get the camera to work, but not having luck.I am using the OctoPi image, but i think my issue is something with how to display the images.

it took me finally realizing that i needed my IP address followed by /webcam/?action=stream

once i did that it showed. but issue is it shows upside down. in Octoprint settings, i just use setting to vertical flip. i’m not sure how to do that in HA. and i dont know how to get to original mjpg_streamer library to set the -vf so on the Pi its always flipped. any thoughts?

Yea, I’ve had to tweak a few things on mine as well to get the camera shooting in 1080p. I think this is what you’re looking for: /boot/octopi.txt

Be sure and check out this link for all available options.

@xstrex - that was it. On my OctoPi I set up the -vf and it’s all working now when showing to the HA. Thanks again for pointing me in the correct direction.

@farstreet - I finally figured out the syntax for having the units converted. Now as I was looking around more, I notice that if I change the main homeassistant branch under unit_system, I can use imperial (which will yield all temperatures for all sensors to be °F) or metric (to yield all as °C).

But ideally i would like to list the yr temperature as °F and the 3D printer temps as °C.

Here is the configuration.yaml code for the Template Sensor

sensor:
    - platform: yr
      monitored_conditions:
        - temperature
        - symbol
    - platform: template
      sensors:
        hotend:
          friendly_name: 'Hotend'
          value_template: '{{ ((states.sensor.octoprint_actual_tool0_temp.state | float-32) | float*(5/9)) | round(2) }}'
          unit_of_measurement: "°C"
        bed:
          friendly_name: "Bed"
          value_template: '{{ ((states.sensor.octoprint_actual_bed_temp.state | float-32) | float*(5/9)) | round(2) }}'
          unit_of_measurement: "°C"

I’ve set the overall unit_system to imperial, so I’m getting °F, but with my conversion, I’m was trying to get it to show °C for the 3D printer.

Any ideas how to do this? (i’ve tried calling out unit_of_measurement at the template sensor as well as in the customize sections. Neither had any affect to overrule the unit_system. I also tried to just comment out the unit_system, but i believe the default is metric, so everything showed as °C)

here is my UI

@xstrex - what did you end up putting in the /boot/octopi.txt, and for the 1080p? I tried a few more if the options i got from https://github.com/foosel/OctoPrint/wiki/MJPG-Streamer-configuration but most seemed to fail.

currently, i have this working (i used -fps 20 to try and speed up the frames per second, because OctoPi default has a significant lag/delay)

camera_raspi_options="-fps 20 -vf"

@IROTRAS you’ll have to check what resolution your camera actually supports first, otherwise it will fail. Check it with: sudo lsusb -v |grep wWidth
That should get you to the right area, might have to hit space a few times. But eventually you’ll end up with a table showing all supported resolutions. Let me dig out my config, and I’ll ping ya back.

EDIT: that might not work as expected, are you using a pi camera? I’m not, I’m using a USB webcam.

@xstrex - yes, I’m using the Pi camera. And I’m pretty sure it’s the v1 model. I noticed that if I click on the camera image from HA UI page, another screen opens up and that video is much better with respect to the lag. So it’s looking pretty good.

Eventually I’ll probably upgrade to a better camera. But next step is to just get some better lighting - hoping to integrate some LEDs and then have them as another switch in HA.

Appreciate your input and help a ton!

So it looks like you can get 1080p video out of the pi camera v1, though I’m not exactly sure how, but I’m sure google has a few suggestions. And yes, the image in the HA UI is a snapshot that updates every so often, but if you click on the image you get the live (proxy’ed) stream, that’s normal behavior, and performs the same for any other camera in HA.

As for the LED lights, I actually just finished a project doing exactly that. Though my LEDs aren’t controlled by HA (by design), but are controlled by Octopi via GCode. Information on that here and here. The reason I chose the GCode route, was because the lights are only needed when I’m actually printing something, or when I turn them on manually. With the above plugin and setup, you can use commands like “M150 R U B” in your starting GCode, followed by “M150” in your ending GCode. This works exactly as expected, every time. Lights turn on (white), print starts … print ends, lights turn off. Which makes shooting time-lapse video of the prints a lot more visible! Hope some of these help! Let me know if you’d like some of my STL’s and design files for the LED power control module.

Did you ever figure this out? I’m trying to accomplish the same thing. Not sure why the OctoPrint support converts in the first place since even in the US we all use Centigrade with our printers. LOL

Hey, I got some help from @bruhautomation on this and it was easier than I thought - just remove the unit of measurement line from your template sensor and everything shows up proper.

If you’re not familiar with @bruhautomation, he has an awesome channel on YouTube dedicated to Home Automation in general and HASS specifically. I can’t express enough how much subscribing has made all the difference in utilizing Home Assistant. When I started out, I’d never even seen a Pi before. With his help, I’ve gotten so involved that I am now a moderator here and I credit him for a lot of that. You owe it to yourself to check out his channel:

https://www.youtube.com/channel/UCLecVrux63S6aYiErxdiy4w

Here’s how I set up my sensors in my sensors.yaml file (it’s under my other template sensors, so platform: template may be necessary if your setup is different):

#
#
#  OctoPrint Sensor conversions
#
#

     hotend:
       friendly_name: 'Hotend Actual'
       value_template: "{{ ((states.sensor.octoprint_actual_tool0_temp.state | float-32) | float*(5/9)) | round(2) }} °C"
       
     bed:
       friendly_name: 'Bed Actual'
       value_template: "{{ ((states.sensor.octoprint_actual_bed_temp.state | float-32) | float*(5/9)) | round(2) }} °C"
       

     hotend_target:
       friendly_name: 'Hotend Target'
       value_template: "{{ ((states.sensor.octoprint_target_tool0_temp.state | float-32) | float*(5/9)) | round(2) }} °C"
       
     bed_target:
       friendly_name: 'Bed Target'
       value_template: "{{ ((states.sensor.octoprint_target_bed_temp.state | float-32) | float*(5/9)) | round(2) }} °C"
2 Likes

@rpitera thank you for that last piece! And yes, I do follow Ben over at BRUHAutomation. He has been very helpful.

That was the trick that ended up changed so the Octoprint sensors are in °C and my unit_system can remain °F.

Now its looking great. thanks again.

1 Like

Anyone been able to manage octopi from HASS like switches to pause/stop the print if needed

1 Like

I think this would be the ideal state - remotely watching would be more valuable if you were able to start/stop prints. Did you find a solution for this?