RS 1.2.1 and HomeAssistant Integration broken?

I just updated from RS 1.2.0 to 1.2.1 and the entities no longer appear in HomeAssistant.

I have had HA and RS working together for a good 6 months and never had an issue before with upgrades..

Anything I can check to see why its not working? The webcam feed, not via the RS API, works still.
«1

Comments

  • edited December 2021
    HomeAssistant setup as per https://www.home-assistant.io/integrations/repetier
    This is the setup:
    #RS
    repetier:
      - host: 127.0.0.1
        api_key: KEY_HERE
    camera:
      - platform: mjpeg
        name: RS Camera
        still_image_url: http://127.0.0.1:8080/?action=snapshot
        mjpeg_url: http://localhost:8080/?action=stream
    
    
    The HA Log reports an error with the RS integration, it is missing "activeExtruder":

    Logger: homeassistant.setup
    Source: components/repetier/__init__.py:237 < https://github.com/marthoc/home-assistant/blob/dev/homeassistant/components/repetier/__init__.py >
    First occurred: 10:06:59 PM (1 occurrences)
    Last logged: 10:06:59 PM

    Error during setup of component repetier
    Traceback (most recent call last):
      File "/usr/src/homeassistant/homeassistant/setup.py", line 249, in _async_setup_component
        result = await task
      File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/usr/src/homeassistant/homeassistant/components/repetier/__init__.py", line 192, in setup
        api.update()
      File "/usr/src/homeassistant/homeassistant/components/repetier/__init__.py", line 237, in update
        printer.get_data()
      File "/usr/local/lib/python3.9/site-packages/pyrepetier/clsprinter.py", line 104, in get_data
        self._activeextruder = data['activeExtruder']
    KeyError: 'activeExtruder'
    

    It seems someone reported an issue earlier on another location - https://github.com/home-assistant/core/issues/59430 . this was working for me 2 days ago on the current HA version with RS 1.2.0; I updated to 1.2.1 today and noticed it was not; maybe something else is the cause?
  • edited December 2021
    Looking at the API: IPAddress/printer/list/?apikey=KEY

    {"data":[{"active":true,"job":"none","jobid":0,"name":"Aquila","online":1,"pauseState":0,"paused":false,"slug":"Aquila"},{"active":true,"job":"none","jobid":0,"name":"Ender 3 v2","online":0,"pauseState":0,"paused":false,"slug":"Ender_3_v2"},{"active":true,"job":"none","jobid":0,"name":"Ender 6","online":0,"pauseState":0,"paused":false,"slug":"Ender_6"}]}

    And then the printer slug level IPAddress/printer/api/Aquila?a=stateList&apikey=KEY

    {"Aquila":{"activeExtruder":0,"autostartNextPrint":false,"condition":1,"conditionReason":"","debugLevel":6,"doorOpen":false,"extruder":[{"error":0,"output":0.0,"tempRead":29.2,"tempSet":0.0}],"fans":[{"on":false,"voltage":0}],"filterFan":false,"firmware":"Marlin","firmwareStyle":"marlin","firmwareURL":"","flowMultiply":100,"hasXHome":true,"hasYHome":true,"hasZHome":true,"heatedBeds":[{"error":0,"output":0.0,"tempRead":34.7,"tempSet":0.0}],"heatedChambers":[],"layer":2,"lights":0,"notification":"Aquila Ready.","numExtruder":1,"powerOn":true,"rec":false,"sdcardMounted":true,"shutdownAfterPrint":false,"speedMultiply":100,"volumetric":false,"x":150.5229949951172,"y":148.2550048828125,"z":0.2000000029802322},"Ender_3_v2":{"condition":5,"conditionReason":"","firmwareStyle":"marlin"},"Ender_6":{"condition":5,"conditionReason":"","firmwareStyle":"marlin"}}

    Should the SLUG level API return to the other printers as well? Should it be limited to just in my query the Aqulia? I have not updated the HomeAssistant for several months and on the 2021.8 build.


    Looking inside the clsprinter.py file on my HA installation, the error is around the ActiveExtruder -

    rawdata = self._request(self._baseurl + '/printer/api/' + self._slug + '?a=stateList&' + self._apikey)
            data = None
            try:
                data = rawdata[self._slug]
            except:
                pass
    
            if data is None:
                return
    
            if self._job == "none":
                self._job = None
    
            self._activeextruder = data['activeExtruder']

    To my understanding of the code, its fetching the same URL as I tested above. Then going into the array under the slug. Therefore, it should work as expected.. or am I crazy..

    Near the top of the PY file is the set command for the apikey as follows: self._apikey = apikey
    >> is it missing the apikey= part for the URL like in my manual query or is this stored in "apikey"
  • I don't have HA so can not say much about it. stateList only has gotten some more fields, but as your test already showed it is still returning activeExtruder. stateList returns for all printers, so queried slug should always be included, except you did a fresh install and slug name has changed.

    One problem might be that it uses
    https://pypi.org/project/pyrepetier/3.0.5/#files

    which points to non existent github url, so guess that project was abadonned.

    On the other side our answer has not really changed, so see no reason that it should not work if it did before.
  • edited December 2021
    Thank you. I am not sure what would cause the issue other than the upgrade to 1.2.1 for RS.

    Is it safe to downgrade my RPi back to 1.2.0 for testing?

    Would there be any logs within RS for the API calls to see if its calling the correct endpoint/apikey?
  • I think downgrading for testing is no problem. Only wizards might be a weak point but they already existst in some form in 1.2.0. I think format was the same.

    There is no log for all the communication. Normally you see it in server for our gui if needed so wanting to reduce writes for pi and safe a lot of disk space. Only way would be a network sniffer like wireshark on windows. 
  • Thanks. Ill hopefully get some time next week to have a play.

    Im not sure how easily i can get wireshark on the Pi for local traffic.. maybe ill install RS on another box and see if i can trouble shoot it that way.

    Once i get it fixed, ill post back
  • I am SO happy I go through these forums once a week or so. I had no idea that HA had integration with RS!
  • I have the same issue.

    Today I updated Repetier Server to 1.2.1 and the HA integration is not working anymore.
    The HA integration is also outdated and definitely needs some love, but the developer has no time/interest doing so.
  • edited December 2021
    Just upgraded to RS 1.2.1 this morning and I can confirm the Home Assistant integration now fails to startup. As mentioned above, it is erroring with: KeyError: 'activeExtruder'

    Looking at the WebSocket responses, activeExtruder is (now) only returned if a printer is powered on. The HA integration is explicitly looking for that key so fails on startup if it is not present (for any installed printer). I tried powering on all of my printers, restarted Home Assistant and with all the printers on, the Home Assistant integration starts without issue. I have posted my findings on the HA Github, but there has obviously been a change in RS 1.2.1 which no longer exposes the activeExtruder key if a printer is off.

  • Update to the above. Although my actions allowed the HA integration to start, it is still borked. Sensors are not updating. This has to be down to a change (intentional or otherwise) in the latest RS version. The integration was working perfectly well before updating to 1.2.1
  • The problem is that we now send a state also for disconnected printers as we had added 2 variables that are needed in that case. But not connected the other variables make no sense and are not send. So there needs one line be changed in clsprinter.py to test if this is the case. We are checking a way to commit that change to HA.
  • Repetier said:
    The problem is that we now send a state also for disconnected printers as we had added 2 variables that are needed in that case. But not connected the other variables make no sense and are not send. So there needs one line be changed in clsprinter.py to test if this is the case. We are checking a way to commit that change to HA.
    Thank you!
    I would be happy to test on my HA installation if it would assist.
  • edited December 2021
    As an aside question - with the changes to the API in 1.2.1 to include the offline printers - would it be feasible to have the offline ones not returned in a different endpoint/param to exclude?

    Having said that, the Try/Catch to obtain the Raw Data based on the Slug (data = rawdata[self._slug]) in clsprinter.py should not actually be fetching the other printers data anyway..

    Anyway, I am happy to test as needed as well. Thanks again for the awesome support!


  • I just created a pull request on HA github page with a fix, so its pretty likely that in the next homeassistant update the issue will be gone
  • Thank you!
  • Is there somewhere a v1.2.0 PI Image I can download for testing? Because with the v1.2.1 I can't even integrade it in Home Assistant. Or could someone provide a Link to the Image?

    Kind regards,
    Gurry
  • With latest plugin version it should now also work for 1.2.0.
    Hopefully next week we also have a new update 1.2.2 with MQTT including direct homeassistant integration. No plugin required than any more. Works already great in my test and we can provide better support as for an outdated plugin from 3rd party.
  • edited February 2022
    Sounds good. I'm sorry if this is a dumb question but I'm totally new to repetier server and home assistant: how do I update to the latest plugin version?null
  • Just go in Home Assistant to settings  and check core version if there is an update available. I have a translated version so links in english are different, but for me it is the first entry in settings.

    Current version is 2022.2.3
  • Repetier said:
    Just go in Home Assistant to settings  and check core version if there is an update available. I have a translated version so links in english are different, but for me it is the first entry in settings.

    Current version is 2022.2.3
    Ok, now it is working. Thank you.
  • Thanks for that integration.
    Unfortunately there seem to remain 2 problems :
    When trying to get the job_start and job_end sensor. the integration fails with this error message.
    It would be very nice, if you could do something about it.
    Thanks in advance

    Logger: homeassistant.components.sensor
    Source: components/sensor/__init__.py:398
    Integration: Sensor (documentation, issues)
    First occurred: 15:20:41 (2 occurrences)
    Last logged: 15:20:41

    Error adding entities for domain sensor with platform repetier
    Error while setting up repetier platform for sensor
    Traceback (most recent call last):
    File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
    File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 673, in _async_add_entity
    await entity.add_to_platform_finish()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish
    self.async_write_ha_state()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
    self._async_write_ha_state()
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 570, in _async_write_ha_state
    state = self._stringify_state(available)
    File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _stringify_state
    if (state := self.state) is None:
    File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 398, in state
    raise ValueError(
    ValueError: Invalid datetime: sensor.anet_et4_job_start provides state '2022-09-01 15:15:26', which is missing timezone information



  • Ok, sorry I just found updated to version 1.41
    Everthing seems to be working perfectly.
    Thanks
  • will HA turn off and on my Kasa Smart plug or is this just so Alexa can tell me the print finished?
  • There is no automatic connection. If you use HA mosquito it will publish the printer and server entities to HA to be used. How and for what you use them is up to you. In our example integration we show how to make a mini GUI to be included so you see print state and can stop/pause/see file/webcam. You can also add rules to connect print finished with plug, but if you want to shut down every finished print I would doubt, also you need to shut down pc first before disabling it. But you could e.g. use it to implement a clean shutdown for example you send HA to shut down power in 30s and then start shutdown of pc, so ha can execute the shutdown. Not sure how to do it exactly in HA but sure it is possible to add delays there. And you can send own messages to MQTT to trigger such an action.
  • You can turn off your printer using you plug and defining an automation that reakts on the printers states.

    It would be a great feature, if we could shutdown the Repetier Server via a button like the pause,stop,continue buttons. That way, we could define an automation that shuts down the server and switches it off after it is safely down.

  • @umtauscher
    Yes, this is the automation i have working currently in Klipper,  I also have a small program in Linux that shuts down the computer at a certain time, i only used it for my late night prints.  It runs off the Idle timeout period.

    [gcode_macro POWEROFF]
    gcode:
    M117 Shutting down!
        {action_call_remote_method("set_device_power",
                                 device="Printer_plug",
                                 state="off")}
    UPDATE_DELAYED_GCODE ID=delayed_printer_off DURATION=1
  • ok, that shuts down the printer after a M117 command.

    My intention ist to safely shutdown Repetier Server (Rapberry) before switching off the power.
    I my installation the Repetier Server is powered by the same circuit that powers the printers.
  • ... and another idea:
    It would be nice, if Repetier would send a last message to MQTT before shutting down with anything that would represent the downstate. Other MQTT devices for example have a status field that show online or offline.
  • Both on same plug is a bit difficult since pi must shutdown and then it can not send message. So HA might be the help if you trigger a delayed shutdown.

    MQTT messages only stay if the retain flag is enabled. You can send your own message/topic using

    @mqttPublish topic message [QoS] [retain]

    Publishes message with the topic topic. Use this for specialized messages to other devices that need this as input.

    QoS is the Quality Of Service and can be 0 (try to send to subscribers), 1 (ensure at least one receive to subscribers) or 2 (ensure 1 message per subscriber) with default 0. Higher quality means higher latency.

    retain can be 0 or 1. With 1 the message will be kept on broker, while with 0 the message will disappear after disconnection.


    So a power off function might look like this:

    @func shutdown
    @execute shutdown
    @endfunc
    @func powerOff
    @mqttPublish your message
    @timedCall powerOff 2000 shutdown
    @endfunc

    You can add it in run on connect if you like. Then you can call it from everywhere. Not handled by klipper directly, but who cares as long as job is done. It sends topic, waits 2 seconds so mqtt has received it and then calls shutdown.

    HA must of course delete the topic once seen so it does not always power off since the retain will keep it for ever or as long as MQTT runs.

  • @umtauscher
    if both are on the same circuit, you can maybe add one of the Kasa Smart Plugs dedicated to the printer, then you can first shut off the plug to the printer and then the server.  That is how i have mine setup and trying to get it to work.

    @Repetier
    are you saying i can add additional functions to MQTT for each of the ones you listed? then the @mqttPublish would be the IP address of the Smart Plug?  Is it actually that simple?
Sign In or Register to comment.