Advertisement
JLindvig

Greentel/Parsehub

Apr 21st, 2020
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.75 KB | None | 0 0
  1. greentel:
  2.   sensor:
  3.     - platform: template
  4.       sensors:
  5.         talktime:
  6.           friendly_name: "Taletid"
  7.           entity_id: sensor.greentel_status
  8.           unit_of_measurement: "%"
  9.           value_template: >-
  10.             {{ ( ( (state_attr("sensor.greentel_status", "Tale") | replace(',', '.') | float ) / (state_attr("sensor.greentel_status", "Tale_MAX") | replace(',', '.') | float ) ) * 100 ) | round }}
  11.           icon_template: mdi:phone-in-talk
  12.           attribute_templates:
  13.             used: >-
  14.               {{ state_attr("sensor.greentel_status", "Tale") }}
  15.             total: >-
  16.               {{ state_attr("sensor.greentel_status", "Tale_MAX") }}
  17.  
  18.     - platform: template
  19.       sensors:
  20.         data:
  21.           friendly_name: "Data"
  22.           entity_id: sensor.greentel_status
  23.           unit_of_measurement: "%"
  24.           value_template: >-
  25.             {{ ( ( (state_attr("sensor.greentel_status", "Data") | replace(',', '.') | float ) / (state_attr("sensor.greentel_status", "Data_MAX") | replace(',', '.') | float ) ) * 100 ) | round }}
  26.           icon_template: mdi:signal-cellular-3
  27.           attribute_templates:
  28.             used: >-
  29.               {{ state_attr("sensor.greentel_status", "Data") }}
  30.             total: >-
  31.               {{ state_attr("sensor.greentel_status", "Data_MAX") }}
  32.  
  33.     - platform: template
  34.       sensors:
  35.         text:
  36.           friendly_name: "SMS"
  37.           entity_id: sensor.greentel_status
  38.           unit_of_measurement: "%"
  39.           value_template: >-
  40.             {{ ( ( (state_attr("sensor.greentel_status", "SMS") | replace(',', '.') | float ) / (state_attr("sensor.greentel_status", "SMS_MAX") | replace(',', '.') | float ) ) * 100 ) | round }}
  41.           icon_template: cellphone-text
  42.           attribute_templates:
  43.             used: >-
  44.               {{ state_attr("sensor.greentel_status", "SMS") }}
  45.             total: >-
  46.               {{ state_attr("sensor.greentel_status", "SMS_MAX") }}
  47.  
  48.     - platform: template
  49.       sensors:
  50.         data_modem:
  51.           friendly_name: "Modem"
  52.           entity_id: sensor.greentel_status
  53.           unit_of_measurement: "%"
  54.           value_template: >-
  55.             {{ ( ( (state_attr("sensor.greentel_status", "Data_Modem") | replace(',', '.') | float ) / (state_attr("sensor.greentel_status", "Data_Modem_MAX") | replace(',', '.') | float ) ) * 100 ) | round }}
  56.           icon_template: mdi:signal-4g
  57.           attribute_templates:
  58.             used: >-
  59.               {{ state_attr("sensor.greentel_status", "Data_Modem") }}
  60.             total: >-
  61.               {{ state_attr("sensor.greentel_status", "Data_Modem_MAX") }}
  62.  
  63.   shell_command:
  64.    # Følgende skal ændres i kommandoerne
  65.     # PARSEHUB_PROJECT_TOKEN
  66.     # PARSEHUB_API_TOKEN
  67.     # HA_API_TOKEN
  68.     # HA_URL
  69.     greentel_scrape: 'curl -X POST -d "api_key=PARSEHUB_API_TOKEN" "https://www.parsehub.com/api/v2/projects/PARSEHUB_PROJECT_TOKEN/run"'
  70.     greentel_get: 'rm -f greentel.json; curl -X GET "https://www.parsehub.com/api/v2/projects/PARSEHUB_PROJECT_TOKEN/last_ready_run/data?api_key=PARSEHUB_API_TOKEN" | gunzip > greentel.json; curl -X POST -H "Accept: application/json" -H "Authorization: Bearer HA_API_TOKEN" -H "Content-Type: application/json" -d "{\"state\": \"$(date +%s)\", \"attributes\": $(cat greentel.json)}" http://HA_URL/api/states/sensor.greentel_status; rm -f greentel.json'
  71.  
  72.   automation:
  73.     - alias: "Greentel hent værdier"
  74.       trigger:
  75.         - platform: homeassistant
  76.           event: start
  77.         - platform: time
  78.           at: "04:20:00"
  79.       action:
  80.         - service: shell_command.greentel_get
  81.  
  82.     - alias: "Greentel scrape"
  83.       trigger:
  84.         - platform: time
  85.           at: "04:00:00"
  86.       action:
  87.         - service: shell_command.greentel_scrape
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement