Skip to content

Instantly share code, notes, and snippets.

@SamueldaCostaAraujoNunes
Created June 22, 2024 04:25
Show Gist options
  • Save SamueldaCostaAraujoNunes/d8686ae3a5ec599780eaa6aad00042ba to your computer and use it in GitHub Desktop.
Save SamueldaCostaAraujoNunes/d8686ae3a5ec599780eaa6aad00042ba to your computer and use it in GitHub Desktop.
mqtt:
sensor:
- name: "saturn_3_ultra_id"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Id }}'
- name: "saturn_3_ultra_current_status"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set status = value_json.Data.Status.CurrentStatus %}
{% if status == 0 %}
Pronto
{% elif status == 1 %}
Imprimindo
{% else %}
{{ status }} - Desconhecido
{% endif %}
- name: "saturn_3_ultra_previous_status"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set status = value_json.Data.Status.PreviousStatus %}
{% if status == 0 %}
Pronto
{% elif status == 1 %}
Imprimindo
{% else %}
{{ status }} - Desconhecido
{% endif %}
- name: "saturn_3_ultra_print_status"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set status = value_json.Data.Status.PrintInfo.Status %}
{% if status == 0 %}
Pronta
{% elif status == 1 %}
Iniciando
{% elif status == 2 %}
Descendo
{% elif status == 3 %}
Curando Camada
{% elif status == 4 %}
Subindo
{% elif status == 5 %}
Estacionando
{% elif status == 7 %}
Pausada
{% elif status == 16 %}
Completa
{% else %}
{{ status }} - Desconhecido
{% endif %}
- name: "saturn_3_ultra_print_current_layer"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.PrintInfo.CurrentLayer }}'
- name: "saturn_3_ultra_print_total_layer"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.PrintInfo.TotalLayer }}'
- name: "saturn_3_ultra_print_current_ticks"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.PrintInfo.CurrentTicks }}'
- name: "saturn_3_ultra_print_total_ticks"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.PrintInfo.TotalTicks }}'
- name: "saturn_3_ultra_print_error_number"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.PrintInfo.ErrorNumber }}'
- name: "saturn_3_ultra_print_filename"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set filename = value_json.Data.Status.PrintInfo.Filename %}
{{ filename | replace('.goo', '') }}
- name: "saturn_3_ultra_transfer_status"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.FileTransferInfo.Status }}'
- name: "saturn_3_ultra_transfer_download_offset"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.FileTransferInfo.DownloadOffset }}'
- name: "saturn_3_ultra_transfer_check_offset"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.FileTransferInfo.CheckOffset }}'
- name: "saturn_3_ultra_transfer_file_total_size"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.FileTransferInfo.FileTotalSize }}'
- name: "saturn_3_ultra_transfer_filename"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.Status.FileTransferInfo.Filename }}'
- name: "saturn_3_ultra_mainboard_id"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Data.MainboardID }}'
- name: "saturn_3_ultra_timestamp"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set total_seconds = value_json.Data.TimeStamp | int %}
{% set days = (total_seconds // 86400) %}
{% set hours = ((total_seconds % 86400) // 3600) %}
{% set minutes = ((total_seconds % 3600) // 60) %}
{% set seconds = (total_seconds % 60) %}
{% if days > 0 %}
{{ days }}d {{ hours }}h {{ minutes }}m {{ seconds }}s
{% elif hours > 0 %}
{{ hours }}h {{ minutes }}m {{ seconds }}s
{% elif minutes > 0 %}
{{ minutes }}m {{ seconds }}s
{% else %}
{{ seconds }}s
{% endif %}
template:
- sensor:
- name: "saturn_3_ultra_print_progress"
unit_of_measurement: "%"
state: >
{% if states('sensor.saturn_3_ultra_print_current_layer') | int > 0 and states('sensor.saturn_3_ultra_print_total_layer') | int > 0 %}
{{ (states('sensor.saturn_3_ultra_print_current_layer') | float / states('sensor.saturn_3_ultra_print_total_layer') | float * 100) | round(1) }}
{% else %}
0
{% endif %}
availability: >
{{ states('sensor.saturn_3_ultra_print_current_layer') not in ['unknown', 'unavailable'] and
states('sensor.saturn_3_ultra_print_total_layer') not in ['unknown', 'unavailable'] }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment