Adding Snapmaker to HA (need help on making UDP updatable sensors)

Hi Guys,

Searched a lot about this but couldn’t find anyone else but one guy challenging this one.

The goal: Getting details of my AIO Snapmaker A350T into Home Assistant so I can create automations like:

  • Notify me using the HA app when the print/CNC/Laser Engrave/Cut job finishes
  • Turning a colored light indicator in the living room to show the status (Idle/ In progress/Failed/Offline.

During my research I’ve found this page:
Snapmaker 2.0 and Home Assistant - steffr.ch

Overhere the hero behind this Blog page states:
“Did you know that it’s possible to discover your Snapmaker 2.0 in your LAN? Just send an UDP discover Broadcast to Port 20054 and your Snapmaker will reply with his IP-Address, Model-Name and Status.”

He also explained how to add the thing to sensors which are updated by running the python script.

I tried but I just dont get the part on how to implement the sensors with webhook.
I got stuck on translating his automation trigger with the sensor part of the Yaml file on that page:
image

Any help would be appreciated.

Thanks in advance.

1 Like

Hi there Soepgroenten!

This hero is actually me :wink:
I wrote the yaml script you mentioned in the templates.yaml.
After this, you can create your automation.
For example:

alias: Snapmaker Notify Finish
description: Notify finished printjob
trigger:
  - platform: state
    entity_id:
      - sensor.snapmaker_state
    from: RUNNING
    to: IDLE
condition: []
action:
  - service: notify.notify_me
    data:
      title: Snapmaker
      message: Snapmaker finished!
mode: single

If you have more questions, just ask me!

Regards
Stefan

1 Like

Hi Stefan,

Not very common to be able to chat with heroes :slight_smile: but here we are.

Thanks a lot for posting your reply. It made things clear and pointed me in the right direction.

For me it’s working like a charm now:

As I don’t a have a second rpi I decided to run the Python script via the task scheduler of my Synology NAS which also works perfectly

Regards,

Mathijs

2 Likes

Hello,

first thank you

i want ask is how you make the sensor work ?
i have same problem I got stuck on translating his automation trigger with the sensor part of the Yaml file on that page

and will be nice if work with other values like process, temperatures, enclosure state etc.

like @Guybrush_T mention in:

like if we open enclosure door the light turn on inside the enclosure and more.

thank you

I got my templates in separate yaml files so I created a separate snapmaker.yaml file into a subfolder called templates. this is imported into the config file by adding this line to the config file:
template: !include templates/snapmaker.yaml

The contents of the snapmaker.yaml file is a 1 on 1 copy of the Stefan’s code on his webpage but then with the webhook ID you want to give to it.

After a restart you’ll get your sensors which will be updated by the webhook.

The python script can be run from any machine (including your home assistant host) which is capable of running python scripts. Stefan has a separate RPI for that, I added it to my NAS (Synology in my case but qnap etc is also able to run python scripts scheduled).
How you want to run the python script is totally up to you

As by default the webhook is only accessible locally make sure you’ll let the python script communicate to your ha instance by it’s local address…I got a Nabu Casa Cloud subscription and make use of a custom domain so I decided to let the python script connect to my HA’s local IP over the default port (e.g. http://:8123 ← take note of http:// instead of https://)

This should get you going :slight_smile:

Regarding the request for more functions: I agree to that but this will make things more complicated as not everything can be read without the need to authenticate to the device… so it will make things more complex.

For now I’m glad I can notify myself when the job finishes :slight_smile:

In the end I hope for an official integration with HA but this is a very good working workaround.

1 Like

Hello @Soepgroenten,

I done as you mention the sensor show up in my HA but i never use the script before can’t make it to work i will read more about how to use it and try again.

I will the script run it in HA

thank you

Hi together

I’m happy you find my workaround useful.
Concerning more functions: I would also be happy to have more information like progress, enclosure state and official HA integration. But as long as Snapmaker needs a confirmation on the touchscreen for connections, we will not be able to connect automatically to the API.
Also the connection locks the Touchscreen and if you disconnect, the print-job stops. For more informations on issues see this full thread here:

Regards
Stefan

1 Like

Hello @Guybrush_T,

Thank you so much for taking your time to explain this to me,

and for your work,

question about (if you disconnect, the print-job stops) do you mean same problem with luaban and when print from computer ??

before as you say the if you disconnect the print-job will stops but now when i start the print form luban and dicunnect it while still not finish the print will not stopping mabye they fix with new update ??

Thank you

Hi Mohammad

I do not know if the behavior has changed with the latest update, because I always transfer gcode to the snapmaker and print from there, never directly from Luban.
If I have some time, I will have a look at this.

Regards
Stefan

1 Like

Hello,

Thank you very much and have good day.

Thank you

I did some tests today and it looks promising.
If we use an auth-token which was already allowed on the Touchscreen, then we can connect without a new confirmation. And it’s even possible to connect/disconnect without breaking some jobs.
One ugly thing is, that the Touchscreen is “locked” if a remote connection is active.

I already changed my script to create and use an auth-token. I will publish it later so you can try.
Anyway it would be nice, if someone can write an integration to HomeAssistant. I never did and I am not a programmer, so this will take a looong time :wink:

Look at this quick and dirty solution:

New Script SNStatusV2.py to test here:

There is some complicated thing about getting the Auth-Token.
If it does not work the first time with granting permission on the Touchscreen, just delete the file SMToken.txt and try again.

Would recommend to start the script in manual mode that you can see what happens. After this you can put it again in a cronjob.

Remember: Everytime the script connects, the Touchscreen will be locked.

And here the new template to match all the values:

# Snapmaker JSON Webhook
- trigger:
    - platform: webhook
      webhook_id: wh-snapmakera350
      allowed_methods:
        - POST
        - PUT
      local_only: true
  sensor:
    - name: "Snapmaker State"
      state: "{{ trigger.json.snStatus }}"
    - name: "Snapmaker IP"
      state: "{{ trigger.json.snIP }}"
    - name: "Nozzle Temp"
      unit_of_measurement: "°C"
      state: "{{ trigger.json.snNozzleTemp }}"
    - name: "Nozzle Target Temp"
      unit_of_measurement: "°C"
      state: "{{ trigger.json.snNozzleTaTemp }}"
    - name: "Heated Bed Temp"
      unit_of_measurement: "°C"
      state: "{{ trigger.json.snHeatedBedTemp }}"
    - name: "Heated Bed Target Temp"
      unit_of_measurement: "°C"
      state: "{{ trigger.json.snHeatedBedTaTemp }}"
    - name: "File Name"
      state: "{{ trigger.json.snFileName }}"
    - name: "Progress"
      unit_of_measurement: "%"
      state: "{{ trigger.json.snProgress }}"
    - name: "Elapsed Time"
      state: "{{ trigger.json.snElapsedTime }}"
    - name: "Remaining Time"
      state: "{{ trigger.json.snRemainingTime }}"

BTW: Stay kind with me, I am not a programmer :wink:

1 Like

Great, currently unable to test now (can’t wait) but I’ll test ASAP and report the results back to you.

Thanks in advance for your effort so far.

Greatly appreciated :+1:

Hello,

Thank you for your hard work, I pnly see it today i was traveling it look great.

I will try it

thanks again

I finally found some time to give it a try.

So far so good I succesfully edited,placed and authorized the SNStatusV2.py script to my Snapmaker 2.0 A350ENT
I must say, I’ve had to give it a few tries as my computer was upstairs and the Snapmaker Downstairs and with the script the “Allow Authorization” message is displayed very shortly comparing to Luban. You prolly would’ve laughed watching me at Olympic speeds falling down the stairs in the hurry to make it in time :rofl:

Anyways I made it and the script is connected to it:

So if others want to do this, I strongly suggest to sit next to the snapmaker with a laptop :slight_smile:

Currently I’ve got some issues getting the Sensors in Home assistant, for some reason I don’t get all the configured sensors in the snapmaker.yaml file.

The rare thing is, the sensors I’ve already had are still there, so I expect HA to not take count of my new snapmaker.yaml file.

I’ll keep on testing but so far the .py script is running well, but the yaml file needs some attention.

If I’ve found a solution I’ll post it in here

Please feel free to reply if you’re reading this and got a clue what the root cause can be.

EDIT: Found it :slight_smile: I didn’t made a close look at the new yaml config (just copy pasted the config from the new yaml to my existing one) I didnt mentioned the new sensors weren’t prefixed with Snapmaker whilst I was looking for entities called snapmaker :slight_smile:
I was considering removing my question, but I think other users may found it helpfull to know about this one :wink:

1 Like

Hello!
Cool! Seems like you got it and did not break a leg :wink:
The timeout is defined in the script at the “while not connected” loop:
→ time.sleep(10)
But keep in mind that the Snapmaker also have a timeout (don’t know exactly) and the authorize dialog disappears on the Touchscreen.
I had the laptop near my snapmaker, so I did not realize that this could be a danger to someone falling down some stairs :wink:

Glad you survived!

Btw: You are completely free for naming your sensors. You don’t have to rely on my example yaml.

Regards
Stefan

Ah well I’ve had my exercise that day :slight_smile:

I did rename them with the Snapmaker prefix, I just dint mentioned at first and it works well now.
This evening I’m planning to run the old script and the V2 next to eachother. The old script to keep track on the device (runs every minute), the V2 (excluding the Model/IP/Status) I only use on demand using a switch in HA. This way, my snapmaker’s display won’t get locked when I’m taking control physically on the display of the snapmaker whilst keeping the IP and Status accurate.
Also playing with the toughts of creating an automation when it’s state is “Running”. to frequently check the other details of the V2 script.

Thanks for your work on this one, it works perfectly (the only thing that could make our days better is a real integration but that’s more like a nice to have than a must have. Currently I’m happy with it.

1 Like

That’s a good idea to use the two scripts in parallel!
An integration would be nice, so far I installed the development environment and read some documentation :wink: I hope one day I can present my integration or, at least, the findings in my script will be honoured in an integration from a python-crack :slight_smile:

Hey :slight_smile:

Got my Snapmaker now for a couple of days and stumbled over your script.
Thanks for the work!
I also use home assistant for quite a while but never had the need to write an integration.
But when I saw your request I thought I’d start diving in that rabbithole.
A first proof of concept should be done in a couple of days and as soon as I understood all the HASS concepts with ConfigFlow and DataCoordinator I create a more sophisticated one.
I’ll keep you updated as soon as I have something to show that works.

Greets CCarpo

Btw. do you already have json data examples from the other toolheads?

4 Likes


Looks quite nice to me :slight_smile:
But with an integration, it could present different toolheads metrics…