Guest User

Untitled

a guest
Feb 20th, 2024
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.92 KB | None | 0 0
  1. #ESPHOME yaml(basic stuff not included):
  2.  
  3. ########################################################################################################
  4. #ataxprint remote
  5.  
  6. binary_sensor:
  7.   - platform: gpio
  8.     pin:
  9.       number: GPIO2  #D4
  10.       inverted: true
  11.       mode: INPUT_PULLUP
  12.     name: "ataxprintN3 On/Off"
  13.     filters:
  14.       - delayed_on: 10ms  
  15.   - platform: gpio
  16.     pin:
  17.       number: GPIO0 #D3
  18.       mode: INPUT_PULLUP
  19.       inverted: true
  20.     name: "ataxprint LED On/Off"
  21.     filters:
  22.       - delayed_on: 10ms
  23.  
  24. ########################################################################################################
  25. #Segment display
  26.  
  27. display:
  28.     platform: tm1637
  29.     id: Scale_display
  30.     clk_pin: GPIO5 #D1
  31.     dio_pin: GPIO4 #D2
  32.     intensity: 0
  33.     inverted: false
  34.     lambda: |-
  35.       it.printf(0, "%.1f", round(id(filascale_with_spool).state - id(filament_spool_weight).state)/1);
  36.     update_interval: 5s
  37.  
  38. switch:
  39.   - platform: gpio
  40.     name: Filascale Display ON/OFF
  41.     id: filascale_display_onoff
  42.     pin:
  43.       number: GPIO14 #D5
  44.       inverted: false
  45.  
  46. ########################################################################################################
  47. #Filament scale starts here
  48.  
  49. sensor:
  50.   - platform: hx711
  51.     name: Filascale with spool
  52.     id: filascale_with_spool
  53.     dout_pin: GPIO13 #D7
  54.     clk_pin: GPIO12 #D6
  55.     gain: 128
  56.     filters:
  57.       - calibrate_linear:
  58.          - -162856 -> 0
  59.           - 140041 -> 796
  60.       - round: 1
  61.     unit_of_measurement: g
  62.     update_interval: 5s
  63.  
  64.   - platform: homeassistant
  65.     name: Filament Spool Weight
  66.     id: filament_spool_weight
  67.     entity_id: sensor.filament_spool_weight
  68.  
  69.   - platform: template
  70.     name: Filascale without spool
  71.     id: filascale_without_spool
  72.     lambda: |-
  73.         return (round(id(filascale_with_spool).state - id(filament_spool_weight).state)/1);
  74.     update_interval: 5s
  75.     unit_of_measurement: g
  76.     accuracy_decimals: 0
  77.  
  78. ########################################################################################################
  79. #Python script for image editing(update paths, allow esternal dirs in HASS config yaml):
  80.  
  81. from PIL import Image, ImageDraw, ImageFont
  82. import sys
  83. from datetime import datetime
  84.  
  85. x, y1, y2, y3 = 25, 25, 75, 125
  86. scale_data = str(sys.argv[1])
  87. spool_name = str(sys.argv[2])
  88. current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
  89.  
  90. # Open the desired Image you want to add text on
  91. i = Image.open("/config/python_scripts/filascale.jpg")
  92.  
  93. # To add 2D graphics in an image call draw Method
  94.  
  95. Im = ImageDraw.Draw(i)
  96. mf = ImageFont.truetype("/config/python_scripts/arial.ttf", 40)
  97.  
  98. # thin border
  99. Im.text((x-3, y1), f"Spool name: {spool_name}", (0,0,0), font=mf)
  100. Im.text((x+3, y1), f"Spool name: {spool_name}", (0,0,0), font=mf)
  101. Im.text((x, y1-3), f"Spool name: {spool_name}", (0,0,0), font=mf)
  102. Im.text((x, y1+3), f"Spool name: {spool_name}", (0,0,0), font=mf)
  103.  
  104. Im.text((x-3, y2), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
  105. Im.text((x+3, y2), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
  106. Im.text((x, y2-3), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
  107. Im.text((x, y2+3), f"Spool weight: {scale_data}g", (0,0,0), font=mf)
  108.  
  109. Im.text((x-3, y3),f"{current_datetime}", (0,0,0), font=mf)
  110. Im.text((x+3, y3),f"{current_datetime}", (0,0,0), font=mf)
  111. Im.text((x, y3-3),f"{current_datetime}", (0,0,0), font=mf)
  112. Im.text((x, y3+3),f"{current_datetime}", (0,0,0), font=mf)
  113.  
  114. # Add Text to an image
  115. Im.text((x,y1), f"Spool name: {spool_name}", (255,255,255), font=mf)
  116. Im.text((x,y2), f"Spool weight: {scale_data}g", (255,255,255), font=mf)
  117. Im.text((x,y3), f"{current_datetime}", (255,255,255), font=mf)
  118.  
  119. # Save the image on which we have added the text
  120. i.save("/config/www/"+current_datetime+"_"+spool_name+"_filascale_edited.jpg")
  121.  
  122. #second save for the lovelace picture card to avoid updating the path all the time
  123. i.save("/config/www/filascale_edited.jpg")
  124.  
Advertisement
Add Comment
Please, Sign In to add comment