cmroche / OctoPrint-HomeAssistant

Home Assistant plugin for OctoPrint, enabling MQTT discovery of you device and sensors
110 stars 18 forks source link

File List #65

Open willpuckett opened 3 years ago

willpuckett commented 3 years ago

First, thanks for one of the best, most powerful plugins in the Octoprint ecosystem, as well as the superb documentation for it (especially the safe shutdown script and automation). It's truly transformative.

Is it feasible to be able to display a list of the files in Octoprint's uploads folder and be able to launch jobs via Homeassistant?

thanks again!

willpuckett commented 3 years ago

So, I continued digging and on the way also thought it would be nice to be able to send arbitrary gcode via Home Assistant.

Installing text-input-row (community discussion here), I came up with:

entities:
  - entity: input_text.gcode
    type: 'custom:text-input-row'
  - action_name: Send Gcode...
    icon: 'mdi:keyboard'
    name: ' '
    service: mqtt.publish
    service_data:
      topic: octoPrint/hassControl/commands
      payload_template: "{{ states('input_text.gcode') }}"
    type: call-service
type: entities

But am getting a variable not found kind of thing when I reference input_text.gcode, so I'm obviously doing it slightly wrong... Trying to sort through templates now...

willpuckett commented 3 years ago

I haven't worked out adding a file list, but I did get a terminal field put together today.

In Lovelace config:

views:
  - title: Printers
    path: printers
    badges: []
    cards: []
cards:
  - card:
      type: picture-entity
      entity: camera.axon
    conditions:
      - entity: binary_sensor.axon_printing
        state_not: unavailable
    type: conditional
  - cards:
      - entity: input_text.gcode
        type: 'custom:text-input-row'
      - name: Send...
        tap_action:
          action: call-service
          service: mqtt.publish
          service_data:
            topic: Axon/hassControl/commands
            payload_template: '{{ states("input_text.gcode") }}'
        type: button
    type: horizontal-stack

You'll have to install text-input-row and then add your variable to Home Assistant's configuration.yaml like:

input_text: !include input_text.yaml

And then create an input_text.yaml file with:

gcode:
  icon: 'mdi:keyboard'

Thanks again!

cmroche commented 3 years ago

Thanks for sharing this. I'll leave the issue open and test this myself soon (this weekend if I can find the time) and if it works I'll add it to the examples.

willpuckett commented 3 years ago

I hope it's helpful!

Here's a screenshot: IMG_4362

The only caveat I've found is that to update the input_text variable, I either have to press return after typing it BEFORE pressing the send button, or click outside the field (but not on the send button) to set the variable, and then click send. Of course, I would prefer to be able to simply type the gcode and press enter to have it send, so maybe some more attention this weekend could be useful....

I'm happy to provide better instructions if my earlier ramblings prove uninterpretable 🙃