Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ESPHOME yaml(basic stuff not included):
- ########################################################################################################
- #ataxprint remote
- binary_sensor:
- - platform: gpio
- pin:
- number: GPIO2 #D4
- inverted: true
- mode: INPUT_PULLUP
- name: "ataxprintN3 On/Off"
- filters:
- - delayed_on: 10ms
- - platform: gpio
- pin:
- number: GPIO0 #D3
- mode: INPUT_PULLUP
- inverted: true
- name: "ataxprint LED On/Off"
- filters:
- - delayed_on: 10ms
- ########################################################################################################
- #Segment display
- display:
- platform: tm1637
- id: Scale_display
- clk_pin: GPIO5 #D1
- dio_pin: GPIO4 #D2
- intensity: 0
- inverted: false
- lambda: |-
- it.printf(0, "%.1f", round(id(filascale_with_spool).state - id(filament_spool_weight).state)/1);
- update_interval: 5s
- switch:
- - platform: gpio
- name: Filascale Display ON/OFF
- id: filascale_display_onoff
- pin:
- number: GPIO14 #D5
- inverted: false
- ########################################################################################################
- #Filament scale starts here
- sensor:
- - platform: hx711
- name: Filascale with spool
- id: filascale_with_spool
- dout_pin: GPIO13 #D7
- clk_pin: GPIO12 #D6
- gain: 128
- filters:
- - calibrate_linear:
- - -162856 -> 0
- - 140041 -> 796
- - round: 1
- unit_of_measurement: g
- update_interval: 5s
- - platform: homeassistant
- name: Filament Spool Weight
- id: filament_spool_weight
- entity_id: sensor.filament_spool_weight
- - platform: template
- name: Filascale without spool
- id: filascale_without_spool
- lambda: |-
- return (round(id(filascale_with_spool).state - id(filament_spool_weight).state)/1);
- update_interval: 5s
- unit_of_measurement: g
- accuracy_decimals: 0
- ########################################################################################################
- #Python script for image editing(update paths, allow esternal dirs in HASS config yaml):
- from PIL import Image, ImageDraw, ImageFont
- import sys
- from datetime import datetime
- x, y1, y2, y3 = 25, 25, 75, 125
- scale_data = str(sys.argv[1])
- spool_name = str(sys.argv[2])
- current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
- # Open the desired Image you want to add text on
- i = Image.open("/config/python_scripts/filascale.jpg")
- # To add 2D graphics in an image call draw Method
- Im = ImageDraw.Draw(i)
- mf = ImageFont.truetype("/config/python_scripts/arial.ttf", 40)
- # thin border
- Im.text((x-3, y1), f"Spool name: {spool_name}", (0,0,0), font=mf)
- Im.text((x+3, y1), f"Spool name: {spool_name}", (0,0,0), font=mf)
- Im.text((x, y1-3), f"Spool name: {spool_name}", (0,0,0), font=mf)
- Im.text((x, y1+3), f"Spool name: {spool_name}", (0,0,0), font=mf)
- Im.text((x-3, y2), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
- Im.text((x+3, y2), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
- Im.text((x, y2-3), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
- Im.text((x, y2+3), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
- Im.text((x-3, y3),f"{current_datetime}", (0,0,0), font=mf)
- Im.text((x+3, y3),f"{current_datetime}", (0,0,0), font=mf)
- Im.text((x, y3-3),f"{current_datetime}", (0,0,0), font=mf)
- Im.text((x, y3+3),f"{current_datetime}", (0,0,0), font=mf)
- # Add Text to an image
- Im.text((x,y1), f"Spool name: {spool_name}", (255,255,255), font=mf)
- Im.text((x,y2), f"Spool weight: {scale_data}g", (255,255,255), font=mf)
- Im.text((x,y3), f"{current_datetime}", (255,255,255), font=mf)
- # Save the image on which we have added the text
- i.save("/config/www/"+current_datetime+"_"+spool_name+"_filascale_edited.jpg")
- #second save for the lovelace picture card to avoid updating the path all the time
- i.save("/config/www/filascale_edited.jpg")
Advertisement
Add Comment
Please, Sign In to add comment