Octoprint RestFull switch

@Johann_Edelmuller Great Octoprint page. I use most of the same elements as you. The PrettyGCode is a great addon.

How do you get the iframe to come up with full screen mode in the card? I’m not the best with trying to sort out the html to open the tab in full screen in the card. Here’s what I have so far, but I get the Octoprint page with prettyCode not in full screen.

  - aspect_ratio: 100%
    type: iframe
    url: http://10.0.0.59:5000/?fullscreen=1#tab_plugin_prettygcode

What do I need to add to get it to display in full screen mode like what yours shows?
OK, I found the link to the fullscreen at the bottom once I scrolled up… That works now.

Next question, is there a way to minimize the “State” and “dashboard” , etc as well?

Nice. Are you using a Sonoff Pow or similar for power consumption? This could be used to calculate electricity costs and aggregate a total cost per print. Great for calculating costs when selling prints!

Try this as the Add CSS Code:

/* Make webcam invisible in fullscreen mode. */
.pgfullscreen .gwin #webcam_rotator {
    width: 0px;
}
/* Make buttons invisible in fullscreen mode. */
.pgfullscreen #state_wrapper {
    z-index: -5;
}
.pgfullscreen #tab_plugin_prettygcode .pgstatetoggle {
    z-index: -10;
}
.pgfullscreen #files_wrapper {
    z-index: -6;
}
.pgfullscreen #tab_plugin_prettygcode .pgfilestoggle {
    z-index: -10;
}
.pgfullscreen #tab_plugin_prettygcode .pgdashtoggle {
    z-index: -10;
}
#tab_plugin_prettygcode .fstoggle {
    z-index: -10;
}
.pgfullscreen #tab_plugin_prettygcode .pgcameratoggle {
    z-index: -10;
}
/* Move the GUI Button */
.pgfullscreen#tab_plugin_prettygcode .pgsettingstoggle {
    right: 40px;
}
.pgfullscreen #tab_plugin_prettygcode #mygui {
    right: 40px;
}
/* Trying to get rid of the bloody scrollbars */
.pgfullscreen #tab_plugin_prettygcode .gwin {
    overflow: hidden;
    position: fixed;
}


If anyone knows how to rid of scrollbards…

1 Like

Will try the css code. Thanks

how i can add css styles?

In the plugin, by clicking the Show/Hide Instructions button under the stream.
Let me know if you can get rid of the scrollbars… That should normally do it, but does not:

/* Trying to get rid of the bloody scrollbars */
.pgfullscreen #tab_plugin_prettygcode .gwin {
    overflow: hidden;
    position: fixed;
}
1 Like

thanks for the answer, as far as the scrollbar is concerned, I think it’s because of the iframe in homeassistant.
maybe it works with custom component card-mod ???

Yup, that could be a way to try this. I think it actually comes from the octoprint page. There are multiple layers and a lot of what is hidden is wider and higher than the prettygcode image…

I have the same problem with this error 400. How did you solve this problem ?

I ended up using rest commands I believe. I honestly quit using any of the Hass controls for Octoprint until a way is found to populate a list where you can select the .gcode files that are uploaded to it. Otherwise you still have to go to the Octopi interface to actually print them. To me that kinda defeated the purpose of bringing everything into Hass.

is there a way to turn of the log from octoprint.
I always turn of the pi running octoprint and then my logs are full of connection errors

@Johann_Edelmuller did you upgrade Octoprint recently? My prettygcode view no more works since. I get a ‘refused to connect’ error. I think it’s because of credentials no more being passed on to Octoprint. Including these in the url: ‘http://user:[email protected]’ does not work (no error message, but no load). Any tip is welcome!

Hallo @monkey-house,

i must set this option in octoprint website.

apparently this option was added to an update or whatever :wink:

Wow what a silly option! Thanks for that… Jetzt muss ich wachten 20 Stunden bis dem Druck fertig zu sein!

@Johann_Edelmuller: Not having much luck with this. Here is what is displayed in Hass. Tried with and without CSS, with a different browser, etc. I tried using either the full screen or regular link. Not sure whether this is an issue with the Hass browser, Google Chrome or Octoprint… Here is a screenshot. Can you confirm yours still displays correctly?

I managed to make a restful switch for the connect / disconnect api request in octoprint.

switch:
  - platform: rest
    name: "Brytare - Connect Ender 3 V2"
    resource: http://192.168.1.27/api/connection
    scan_interval: 5
    body_on: '{"command": "connect"}'
    body_off: '{"command": "disconnect"}'
    is_on_template: '{{ value_json.current.state == "Operational" }}'
    headers:
      Content-Type: application/json
      X-Api-Key: your_api_key

It works great - but there´s an error in the logfile:

2020-08-31 10:22:51 ERROR (MainThread) [homeassistant.components.rest.switch] Can’t turn on http://192.168.1.27/api/connection. Is resource/endpoint offline?

One strange thing is that I could NOT get the API request to work by using curl - very odd.

Hi, may I know how do you do this import the control panel and other data like filament usage and cost from octoprint? Do you mind to share me your relevant part of configuration.yaml in HA. Thank you in advance.

Hi, can someone give me a hint, why i’m getting a “bad request”, when trying to curl my octoprint?

 curl http://192.168.1.3:4000/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json'  -H 'X-Api-Key: CC9Cxxxxxxxxxxx1A1'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

Hey guys,

A little advise? If I want to put this in a script to expose to Alexa. How can I do that

shell_command:
  octoprint_pause_resume: "curl -s http://192.168.1.47/api/job -d '{\"command\":\"pause\",\"action\":{\"toggle\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_autohome: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"G28 W\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"

Do I put the above (with correct info) in the config.yaml and then call service “octoprint_pause_resume” as the entity?

Or??.. My first time dealing with calling curl commands from HA

Thanks :slight_smile:

EDIT, think I found it actually

Hi guys. Thanks for this helpful thread.

I could use some help though.
Does anyone know how to parse a number from an input_number entity into the curl commands?
I would like to be able to manually input the temperature target for the bed or nozzle.

EDIT: Never mind. I figured it out. Here’s an example of my shell_command for those who are interested:

shell_command:
set_bed_temp: “curl -s ‘http://192.168.xxx.xx/api/printer/bed’ -d ‘{\"command":\"target",\“target\”:{{states(\“input_number.3d_bed_temp\”)|int}}}’ -H ‘Content-Type: application/json’ -H ‘X-Api-Key: xx’”

2 Likes

Just wanted to thank you for this topic. Works perfectly with my Ender 5!