Octoprint - support for multiple printers

Current octoprint component does only support one printer.
Support for more than one printer would be nice.

I’ll look in to this

Brilliant :slight_smile:
I’ve made an auto-turn-off automation when printing is done for the first printer and it would be nice for the other one too.

Multiple printer is definitly needed! :smile:

Has anyone with multiple octorprint servers tried setting up two?

octoprint:
  host: 192.168.1.2
  password; blahblah

octoprint 2:
  host: 192.168.1.3
  password: blahblah

Not sure it will work, it probably won’t, but would be interesting to see what happens and what error you get if any.

Also would be good to be able to specity a non-80 tcp port, because Octoprint might be on port 5000 now that there’s the handy Octoprint add-on for Hass.io… :slight_smile:

There are two scenarios that need to be looked at.

  1. multiple printers using different ports on one octoprint server
  2. multiple octoprint servers (different IP addresses, same port number).

Any progress on these? The second one is my configuration.

@turboc have you attempted to just set up two octoprint blocks in your config? Like mentioned above?

1 Like

I haven’t tried it, but from a YAML perspective shouldn’t that be invalid??

It tells me that the configuration.yaml contains duplicate keys

No it should be okay. For example check out the cameras listed here https://home-assistant.io/docs/configuration/devices/

Here are the relevant sections of my configuration.yaml and below is the error being thrown in the log.

octoprint miniselect:
  host: fsocto3d.mydomain.com
  api_key: miniselectAPIkey

octoprint prusapi:
  host: prusapi.mydomain.com
  api_key: prusapiAPIkey


sensor:
  - platform: octoprint
    name: miniselect
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage
  - platform: octoprint
    name: prusapi
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage
binary_sensor:
  - platform: ring
    monitored_conditions:
      - ding
      - motion
  - platform: octoprint
    name: selectmini
    monitored_conditions:
      - Printing
      - Printing Error
  - platform: octoprint
    name: prusapi
    monitored_conditions:
      - Printing
      - Printing Error



2018-02-23 20:09:13 ERROR (MainThread) [homeassistant.setup] Error during setup of component octoprint
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/octoprint.py", line 35, in setup
    base_url = 'http://{}/api/'.format(config[DOMAIN][CONF_HOST])
KeyError: 'octoprint'

Thanks for trying! Yeah I guess that makes sense. I’ll have to look in to how HA handles two or more of the same component.

Know of any other components that work that way?

I think to have multiple of the same thing, you have to make it a platform like lights, switch, etc. Then the sensor should be able to reference the individual device of that platform. Not sure though, I haven’t gotten into device development. I tend to stick with apps in AD. :slight_smile:

I have made the changes to the Octoprint platform as well as Sensors and Binary sensors to provide this functionality on my Home Assistant fork which can be found at https://github.com/AmiSMB/home-assistant/tree/multiple_octoprint which I would be grateful is anyone else is willing to test. I have my two printers running on this fine and can access then via the two different ports that they run on internally or via the ddns https url that they are also on for external access.

This allows you to specify multiple Octoprint servers like this:-

configuration.yaml
octoprint:
  - name: MyOctoprint
    host: 192.168.2.1
    port: 5000
    ssl: false
    api_key: !secret MyOctoprintKey
    bed: true
    number_of_tools: 1
  - name: AnotherOctoprint
    host: 192.168.2.1
    port: 5001
    ssl: false
    api_key: !secret AnotherOctoprintKey
    bed: true
    number_of_tools: 1

binary_sensor:
  - platform: octoprint
    name: MyOctoprint
    monitored_conditions:
      - Printing
      - Printing Error
  - platform: octoprint
    name: AnotherOctoprint
    monitored_conditions:
      - Printing
      - Printing Error

sensor:
  - platform: octoprint
    name: MyOctoprint
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage
  - platform: octoprint
    name: AnotherOctoprint
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage

groups.yaml
#################################################################
## Groups
#################################################################

  default_view:
    view: yes
    icon: mdi:home-assistant
    entities:
      - device_tracker.MyOctoprint
      - device_tracker.AnotherOctoprint
      - group.MyOctoprint_status_card
      - group.AnotherOctoprint_status_card

  MyOctoprint_status_card:
    view: no
    name: MyOctoprint Prusa i3 Status
    entities:
      - sensor.MyOctoprint_current_state
      - binary_sensor.MyOctoprint_printing
      - binary_sensor.MyOctoprint_printing_error
      - sensor.MyOctoprint_job_percentage
      - sensor.MyOctoprint_target_bed_temp
      - sensor.MyOctoprint_actual_bed_temp
      - sensor.MyOctoprint_target_tool0_temp
      - sensor.MyOctoprint_actual_tool0_temp

  AnotherOctoprint_status_card:
    view: no
    name: AnotherOctoprint Status
    entities:
      - sensor.AnotherOctoprint_current_state
      - binary_sensor.AnotherOctoprint_printing
      - binary_sensor.AnotherOctoprint_printing_error
      - sensor.AnotherOctoprint_job_percentage
      - sensor.AnotherOctoprint_target_bed_temp
      - sensor.AnotherOctoprint_actual_bed_temp
      - sensor.AnotherOctoprint_target_tool0_temp
      - sensor.AnotherOctoprint_actual_tool0_temp
3 Likes

Just saw this. I’ll try to pull it down and give it a try tomorrow. Has anything changed since this post that I need to be aware of?

I’m getting the following error.

2018-08-31 16:54:59 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform octoprint
  File "/home/homeassistant/homeassistant/lib/python3.6/site-packages/homeassistant/components/binary_sensor/octoprint.py", line 38, in setup_platform
    octoprint_api = hass.data[DOMAIN]["api"]
2018-08-31 16:54:59 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform octoprint
  File "/home/homeassistant/homeassistant/lib/python3.6/site-packages/homeassistant/components/binary_sensor/octoprint.py", line 38, in setup_platform
    octoprint_api = hass.data[DOMAIN]["api"]

Any thoughts?

Could you post the relevant section of your config. I am just in the process of merging the current version of Home Assistant with my changes made to it. I am having problems with the new authentication system in my test system.

I now have a debug version via Docker with the latest code. Looking at your trace back I think that the issue is that you are in the wrong branch. You need to be using the multiple_octoprint branch which has the correct changes. If you pull this branch from my repo and test this version it should be up to date with the latest version of homeassistant. I am going to do a PR and hopefully get it into the next release.

I pulled down the latest copy. Here is what I’m getting now.

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.loader] Loaded sensor.octoprint from custom_components.sensor.octoprint

2018-09-15 11:42:10 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.octoprint which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.loader] Loaded octoprint from custom_components.octoprint

2018-09-15 11:42:10 WARNING (MainThread) [homeassistant.loader] You are using a custom component for octoprint which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.setup] Setting up octoprint

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.octoprint from homeassistant.components.binary_sensor.octoprint

2018-09-15 11:42:10 ERROR (MainThread) [custom_components.octoprint] Endpoint: printer Failed to update OctoPrint status. Error: 409 Client Error: CONFLICT for url: http://192.168.2.125:5000/api/printer

2018-09-15 11:42:10 ERROR (MainThread) [custom_components.octoprint] Endpoint: printer Failed to update OctoPrint status. Error: HTTPConnectionPool(host='192.168.2.29', port=5000): Max retries exceeded with url: /api/printer (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5b2c95b240>: Failed to establish a new connection: [Errno 111] Connection refused',))

2018-09-15 11:42:10 ERROR (MainThread) [custom_components.octoprint] Endpoint: job Failed to update OctoPrint status. Error: HTTPConnectionPool(host='192.168.2.29', port=5000): Max retries exceeded with url: /api/job (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5b2c109780>: Failed to establish a new connection: [Errno 111] Connection refused',))

2018-09-15 11:42:10 INFO (MainThread) [custom_components.octoprint] Finished setting up Octoprint {'fsocto3d': {'api': <custom_components.octoprint.OctoPrintAPI object at 0x7f5b2ced32e8>}, 'prusapi': {'api': <custom_components.octoprint.OctoPrintAPI object at 0x7f5b2cedb2e8>}}

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.setup] Setup of domain octoprint took 0.4 seconds.

2018-09-15 11:42:10 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=octoprint>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Current State: None>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Current State: None>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Actual Tool0 Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Target Tool0 Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Actual Bed Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Target Bed Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_16) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Job Percentage: 0>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Actual Tool0 Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Target Tool0 Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Actual Bed Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Target Bed Temp: 0>

2018-09-15 11:42:11 INFO (SyncWorker_17) [custom_components.sensor.octoprint] Created OctoPrint sensor <Entity Job Percentage: 0>

2018-09-15 11:42:11 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform octoprint

File "/home/homeassistant/homeassistant/lib/python3.6/site-packages/homeassistant/components/binary_sensor/octoprint.py", line 38, in setup_platform

octoprint_api = hass.data[DOMAIN]["api"]

2018-09-15 11:42:11 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform octoprint

File "/home/homeassistant/homeassistant/lib/python3.6/site-packages/homeassistant/components/binary_sensor/octoprint.py", line 38, in setup_platform

octoprint_api = hass.data[DOMAIN]["api"]



octoprint:
  - name: fsocto3d
    host: 192.168.x.y
    port: 5000
    ssl: false
    api_key: <KEY1>
    bed: true
    number_of_tools: 1
  - name: prusapi
    host: 192.168.x.z
    port: 5000
    ssl: false
    api_key: <KEY2>
    bed: true



  - platform: octoprint
    name: fsocto3d
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage
  - platform: octoprint
    name: prusapi
    monitored_conditions:
      - Current State
      - Temperatures
      - Job Percentage


binary_sensor:
  - platform: octoprint
    name: fsocto3d
    monitored_conditions:
      - Printing
      - Printing Error
  - platform: octoprint
    name: prusapi
    monitored_conditions:
      - Printing
      - Printing Error

Looking at the error it seems that it is not running the changed code as it should be octoprint_api = hass.data[DOMAIN][name][“api”] which is why you are getting the error. If you could do another git pull on my repo and try again.