Recently got a 3D printer and quickly setup OctoPrint (fantastic BTW). Then added the Octoprint Integration to HA. I can now see the stats on my 3d printer, Awesome.
So I added a Sonoff to the power cable of the printer so when my prints are done and I am not home I can completely power off the printer.
But what I don’t want happen is to accidentally hit that switch on the front end while the 3d printer is working
the binary sensor is called binary_sensor.3d_printer_printing and the switch is call switch.3d_printer_sonoff
I followed another post about turning on and off a switch only if is a window is open. and tweaked it to fit my needs But i clearly did not do it right. Here is what I have for the code.
#3D Printer Conditional Switch
- platform: template
switches:
3d_printer:
friendly_name: '3D Printer'
value_template: "{{ is_state('sensor.3d_printer_printing', 'off') }}"
turn_on:
service: switch.turn_on
entity_id: switch.3d_printer_sonoff
turn_off:
service: switch.turn_off
data_template:
entity_id: >
{% if is_state('binary_sensor.3d_printer_printing', 'off') %}
entity_id: switch.3d_printer_sonoff
{% else %}
entity_id: switch.null
{% endif %}
entity_id: switch.3d_printer_sonoff