Skip to content

Commit 588e930

Browse files
started 3d printer binding
1 parent 88a8d44 commit 588e930

23 files changed

Lines changed: 2007 additions & 0 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This content is produced and maintained by the openHAB project.
2+
3+
* Project home: https://www.openhab.org
4+
5+
== Declared Project Licenses
6+
7+
This program and the accompanying materials are made available under the terms
8+
of the Eclipse Public License 2.0 which is available at
9+
https://www.eclipse.org/legal/epl-2.0/.
10+
11+
== Source Code
12+
13+
https://github.com/openhab/openhab-addons
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# 3D Printer Binding
2+
3+
This binding integrates FDM 3D printers into openHAB, allowing you to monitor print status, temperatures, and job progress, and to control prints (pause, resume, cancel) and adjust temperatures, print speed, and fan speed.
4+
5+
Three printer firmware/server platforms are supported:
6+
7+
- **PrusaLink** — Prusa printers running PrusaLink firmware (MK4, XL, Mini+, etc.)
8+
- **Klipper** — Klipper firmware printers accessed via the Moonraker REST API
9+
- **OctoPrint** — Any printer managed by an OctoPrint server
10+
11+
## Supported Things
12+
13+
| Thing ID | Description |
14+
|---------------|------------------------------------------------------|
15+
| `prusaprinter`| Prusa printer via the PrusaLink v1 REST API |
16+
| `klipper` | Klipper printer via the Moonraker REST API |
17+
| `octoprint` | Printer managed by an OctoPrint server |
18+
19+
## Discovery
20+
21+
Auto-discovery is not supported. Things must be added manually.
22+
23+
## Thing Configuration
24+
25+
### PrusaLink (`prusaprinter`)
26+
27+
| Parameter | Description | Default | Required |
28+
|-------------------|---------------------------------------------------------------------------------|---------|----------|
29+
| `hostname` | Hostname or IP address of the printer. || Yes |
30+
| `port` | HTTP port of the PrusaLink API. | `80` | No |
31+
| `apiKey` | API key shown in the printer's settings menu under **Network → API Key**. || Yes |
32+
| `username` | Username for PrusaLink (not used for authentication, kept for future use). | `maker` | No |
33+
| `refreshInterval` | How often to poll the printer, in seconds. | `30` | No |
34+
35+
### Klipper (`klipper`)
36+
37+
| Parameter | Description | Default | Required |
38+
|-------------------|---------------------------------------------------------------------------------|---------|----------|
39+
| `hostname` | Hostname or IP address of the Moonraker server. || Yes |
40+
| `port` | HTTP port of the Moonraker API. | `7125` | No |
41+
| `apiKey` | Moonraker API key. Optional when accessing from a trusted local network. || No |
42+
| `refreshInterval` | How often to poll the printer, in seconds. | `30` | No |
43+
44+
### OctoPrint (`octoprint`)
45+
46+
| Parameter | Description | Default | Required |
47+
|-------------------|---------------------------------------------------------------------------------|---------|----------|
48+
| `hostname` | Hostname or IP address of the OctoPrint server. || Yes |
49+
| `port` | HTTP port of the OctoPrint API. | `5000` | No |
50+
| `apiKey` | OctoPrint API key from **Settings → API → Global API Key**. || Yes |
51+
| `refreshInterval` | How often to poll the printer, in seconds. | `30` | No |
52+
53+
## Channels
54+
55+
All three thing types expose the same set of channels.
56+
57+
| Channel ID | Item Type | R/W | Description |
58+
|-------------------------------|----------------------|-----|------------------------------------------------------------------------------------------------------|
59+
| `printer-state` | String | R | Current printer state: `IDLE`, `PRINTING`, `PAUSED`, `FINISHED`, `ERROR`, or `BUSY`. |
60+
| `job-name` | String | R | Name of the file currently loaded or being printed. |
61+
| `job-progress` | Number | R | Print completion percentage (0–100). |
62+
| `time-elapsed` | Number | R | Seconds elapsed since the print started. |
63+
| `time-remaining` | Number | R | Estimated seconds remaining. |
64+
| `nozzle-temperature` | Number:Temperature | R | Current nozzle (hotend) temperature. |
65+
| `nozzle-temperature-setpoint` | Number:Temperature | RW | Nozzle temperature target. Send a temperature to change it. |
66+
| `bed-temperature` | Number:Temperature | R | Current heated bed temperature. |
67+
| `bed-temperature-setpoint` | Number:Temperature | RW | Bed temperature target. Send a temperature to change it. |
68+
| `print-speed` | Number | RW | Print speed as a percentage of the configured profile speed (0–200). Read support varies by firmware.|
69+
| `fan-speed` | Number | RW | Part-cooling fan speed percentage (0–100). Read support varies by firmware. |
70+
| `pause-resume` | Switch | RW | `ON` when the print is paused. Send `ON` to pause, `OFF` to resume. |
71+
| `cancel` | Switch | W | Send `ON` to cancel the current print. Resets to `OFF` automatically. |
72+
73+
## Full Example
74+
75+
### Things
76+
77+
`threedprinter.things`
78+
79+
```java
80+
Thing threedprinter:prusaprinter:mk4 "Prusa MK4" [
81+
hostname="192.168.1.50",
82+
apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
83+
refreshInterval=15
84+
]
85+
86+
Thing threedprinter:klipper:voron "Voron 2.4" [
87+
hostname="voron.local",
88+
port=7125,
89+
refreshInterval=10
90+
]
91+
92+
Thing threedprinter:octoprint:ender "Ender 3 (OctoPrint)" [
93+
hostname="octopi.local",
94+
apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
95+
refreshInterval=20
96+
]
97+
```
98+
99+
### Items
100+
101+
`threedprinter.items`
102+
103+
```java
104+
String MK4_State "Printer state [%s]" { channel="threedprinter:prusaprinter:mk4:printer-state" }
105+
String MK4_JobName "Current job [%s]" { channel="threedprinter:prusaprinter:mk4:job-name" }
106+
Number MK4_Progress "Progress [%.1f %%]" { channel="threedprinter:prusaprinter:mk4:job-progress" }
107+
Number MK4_TimeElapsed "Time elapsed [%d s]" { channel="threedprinter:prusaprinter:mk4:time-elapsed" }
108+
Number MK4_TimeRemaining "Time remaining [%d s]" { channel="threedprinter:prusaprinter:mk4:time-remaining" }
109+
Number:Temperature MK4_NozzleTemp "Nozzle temp [%.1f %unit%]" { channel="threedprinter:prusaprinter:mk4:nozzle-temperature" }
110+
Number:Temperature MK4_NozzleTarget "Nozzle target [%.1f %unit%]" { channel="threedprinter:prusaprinter:mk4:nozzle-temperature-setpoint" }
111+
Number:Temperature MK4_BedTemp "Bed temp [%.1f %unit%]" { channel="threedprinter:prusaprinter:mk4:bed-temperature" }
112+
Number:Temperature MK4_BedTarget "Bed target [%.1f %unit%]" { channel="threedprinter:prusaprinter:mk4:bed-temperature-setpoint" }
113+
Number MK4_PrintSpeed "Print speed [%d %%]" { channel="threedprinter:prusaprinter:mk4:print-speed" }
114+
Number MK4_FanSpeed "Fan speed [%d %%]" { channel="threedprinter:prusaprinter:mk4:fan-speed" }
115+
Switch MK4_PauseResume "Paused" { channel="threedprinter:prusaprinter:mk4:pause-resume" }
116+
Switch MK4_Cancel "Cancel print" { channel="threedprinter:prusaprinter:mk4:cancel" }
117+
```
118+
119+
### Sitemap
120+
121+
`threedprinter.sitemap`
122+
123+
```perl
124+
sitemap threedprinter label="3D Printers" {
125+
Frame label="Prusa MK4" {
126+
Text item=MK4_State
127+
Text item=MK4_JobName
128+
Text item=MK4_Progress
129+
Text item=MK4_TimeElapsed
130+
Text item=MK4_TimeRemaining
131+
Text item=MK4_NozzleTemp
132+
Setpoint item=MK4_NozzleTarget minValue=0 maxValue=300 step=5
133+
Text item=MK4_BedTemp
134+
Setpoint item=MK4_BedTarget minValue=0 maxValue=120 step=5
135+
Slider item=MK4_PrintSpeed minValue=0 maxValue=200 step=10
136+
Slider item=MK4_FanSpeed minValue=0 maxValue=100 step=5
137+
Switch item=MK4_PauseResume label="Pause/Resume"
138+
Switch item=MK4_Cancel label="Cancel Print"
139+
}
140+
}
141+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.openhab.addons.bundles</groupId>
9+
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
10+
<version>5.2.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>org.openhab.binding.threedprinter</artifactId>
14+
15+
<name>openHAB Add-ons :: Bundles :: 3D Printer Binding</name>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.karaf.tooling</groupId>
21+
<artifactId>karaf-maven-plugin</artifactId>
22+
<executions>
23+
<execution>
24+
<id>karaf-feature-verification</id>
25+
<!-- disabled until upstream tp-features updates xtext from 2.43.0.M2 to release (which requires asm 9.9.1+) -->
26+
<phase>none</phase>
27+
</execution>
28+
</executions>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
33+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<features name="org.openhab.binding.threedprinter-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
3+
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
4+
5+
<feature name="openhab-binding-threedprinter" description="3D Printer Binding" version="${project.version}">
6+
<feature>openhab-runtime-base</feature>
7+
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.threedprinter/${project.version}</bundle>
8+
</feature>
9+
</features>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.threedprinter.internal;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
import org.openhab.core.thing.ThingTypeUID;
17+
18+
/**
19+
* The {@link ThreedprinterBindingConstants} class defines all constants used across the binding.
20+
*
21+
* @author openHAB Contributors - Initial contribution
22+
*/
23+
@NonNullByDefault
24+
public class ThreedprinterBindingConstants {
25+
26+
public static final String BINDING_ID = "threedprinter";
27+
28+
// Thing types
29+
public static final ThingTypeUID THING_TYPE_PRUSAPRINTER = new ThingTypeUID(BINDING_ID, "prusaprinter");
30+
public static final ThingTypeUID THING_TYPE_KLIPPER = new ThingTypeUID(BINDING_ID, "klipper");
31+
public static final ThingTypeUID THING_TYPE_OCTOPRINT = new ThingTypeUID(BINDING_ID, "octoprint");
32+
33+
// Channels
34+
public static final String CHANNEL_PRINTER_STATE = "printer-state";
35+
public static final String CHANNEL_JOB_NAME = "job-name";
36+
public static final String CHANNEL_JOB_PROGRESS = "job-progress";
37+
public static final String CHANNEL_TIME_ELAPSED = "time-elapsed";
38+
public static final String CHANNEL_TIME_REMAINING = "time-remaining";
39+
public static final String CHANNEL_NOZZLE_TEMPERATURE = "nozzle-temperature";
40+
public static final String CHANNEL_NOZZLE_TEMPERATURE_SETPOINT = "nozzle-temperature-setpoint";
41+
public static final String CHANNEL_BED_TEMPERATURE = "bed-temperature";
42+
public static final String CHANNEL_BED_TEMPERATURE_SETPOINT = "bed-temperature-setpoint";
43+
public static final String CHANNEL_PRINT_SPEED = "print-speed";
44+
public static final String CHANNEL_FAN_SPEED = "fan-speed";
45+
public static final String CHANNEL_PAUSE_RESUME = "pause-resume";
46+
public static final String CHANNEL_CANCEL = "cancel";
47+
48+
// Printer state values
49+
public static final String STATE_IDLE = "IDLE";
50+
public static final String STATE_PRINTING = "PRINTING";
51+
public static final String STATE_PAUSED = "PAUSED";
52+
public static final String STATE_FINISHED = "FINISHED";
53+
public static final String STATE_ERROR = "ERROR";
54+
public static final String STATE_BUSY = "BUSY";
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.threedprinter.internal;
14+
15+
import static org.openhab.binding.threedprinter.internal.ThreedprinterBindingConstants.*;
16+
17+
import java.util.Set;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.eclipse.jdt.annotation.Nullable;
21+
import org.eclipse.jetty.client.HttpClient;
22+
import org.openhab.binding.threedprinter.internal.handler.KlipperHandler;
23+
import org.openhab.binding.threedprinter.internal.handler.OctoPrintHandler;
24+
import org.openhab.binding.threedprinter.internal.handler.PrusaLinkHandler;
25+
import org.openhab.core.io.net.http.HttpClientFactory;
26+
import org.openhab.core.thing.Thing;
27+
import org.openhab.core.thing.ThingTypeUID;
28+
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29+
import org.openhab.core.thing.binding.ThingHandler;
30+
import org.openhab.core.thing.binding.ThingHandlerFactory;
31+
import org.osgi.service.component.annotations.Activate;
32+
import org.osgi.service.component.annotations.Component;
33+
import org.osgi.service.component.annotations.Reference;
34+
35+
/**
36+
* Factory for creating 3D printer thing handlers.
37+
*
38+
* @author openHAB Contributors - Initial contribution
39+
*/
40+
@NonNullByDefault
41+
@Component(configurationPid = "binding.threedprinter", service = ThingHandlerFactory.class)
42+
public class ThreedprinterHandlerFactory extends BaseThingHandlerFactory {
43+
44+
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_PRUSAPRINTER, THING_TYPE_KLIPPER,
45+
THING_TYPE_OCTOPRINT);
46+
47+
private final HttpClient httpClient;
48+
49+
@Activate
50+
public ThreedprinterHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
51+
this.httpClient = httpClientFactory.getCommonHttpClient();
52+
}
53+
54+
@Override
55+
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
56+
return SUPPORTED_THING_TYPES.contains(thingTypeUID);
57+
}
58+
59+
@Override
60+
protected @Nullable ThingHandler createHandler(Thing thing) {
61+
ThingTypeUID uid = thing.getThingTypeUID();
62+
if (THING_TYPE_PRUSAPRINTER.equals(uid)) {
63+
return new PrusaLinkHandler(thing, httpClient);
64+
}
65+
if (THING_TYPE_KLIPPER.equals(uid)) {
66+
return new KlipperHandler(thing, httpClient);
67+
}
68+
if (THING_TYPE_OCTOPRINT.equals(uid)) {
69+
return new OctoPrintHandler(thing, httpClient);
70+
}
71+
return null;
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.threedprinter.internal.config;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
17+
/**
18+
* Configuration for a Klipper printer accessed via the Moonraker API.
19+
*
20+
* @author openHAB Contributors - Initial contribution
21+
*/
22+
@NonNullByDefault
23+
public class KlipperConfiguration {
24+
public String hostname = "";
25+
public int port = 7125;
26+
public String apiKey = "";
27+
public int refreshInterval = 30;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.threedprinter.internal.config;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
17+
/**
18+
* Configuration for a printer running OctoPrint.
19+
*
20+
* @author openHAB Contributors - Initial contribution
21+
*/
22+
@NonNullByDefault
23+
public class OctoPrintConfiguration {
24+
public String hostname = "";
25+
public int port = 5000;
26+
public String apiKey = "";
27+
public int refreshInterval = 30;
28+
}

0 commit comments

Comments
 (0)