Read Antminer API and show details

sensor

  • platform: rest
    name: miner_asik_1
    method: GET
    headers:
    User-Agent: Home Assistant
    Content-Type: application/json
    resource: http://192.168.1.231/api/v1/summary
    json_attributes:
    • miner
      value_template: ‘1’
      scan_interval: 15
      binary_sensor
  • platform: ping
    host: 192.168.1.231
    count: 2
    scan_interval: 30
    name: asik_1_is_available
    templatesensor
  • sensor:
    • name: dif_temperature
      unique_id: dif_temperature

      friendly_name: “temperature difference between ASIC and oil outlet”

      unit_of_measurement: ‘°C’
      device_class: temperature
      availability: >-
      {{ states(‘sensor.temperature_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘sensor.sonoff_1001499c2c_temperature’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {{ states(‘sensor.temperature_asik_1’) | float(0) -states(‘sensor.sonoff_1001499c2c_temperature’) | float(0) }}

    • name: temperature_asik_1
      unique_id: temperature_asik_1
      unit_of_measurement: ‘°C’
      device_class: temperature
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if is_state(‘sensor.chillertemp_asictemp_history_stats’, ‘unknown’) or is_state(‘sensor.chillertemp_asictemp_history_stats’, ‘unavailable’) -%}
      {% set my_diff = 20 %}
      {%- else %}
      {% set my_diff = states(‘sensor.chillertemp_asictemp_history_stats’) | float %}
      {% if my_diff > 50 %} {% set my_diff = 20 %} {% endif %}
      {% endif %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) -%}
      {{ iif ( is_state(‘sensor.sonoff_1001499c2c_temperature’, ‘unavailable’) , ‘unknown’, states(‘sensor.sonoff_1001499c2c_temperature’) | float + my_diff ) }}
      {%- else %}
      {% if not is_state(‘binary_sensor.miner_state_asik_1’, ‘on’) -%}
      {{ iif ( is_state(‘sensor.sonoff_1001499c2c_temperature’, ‘unavailable’) , ‘unknown’, states(‘sensor.sonoff_1001499c2c_temperature’) | float + my_diff ) }}
      {%- else %}
      {{ iif (my_json.chip_temp.max | int < 100,my_json.chip_temp.max | int , 0 ) }}
      {% endif %}
      {% endif %}

    • name: heshrate_asik_1
      unique_id: heshrate_asik_1
      unit_of_measurement: ‘Th’
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {{ (my_json.average_hashrate | int(0)) }}

    • name: power_asik_1
      unit_of_measurement: “kW”
      state_class: measurement
      device_class: power
      unique_id: power_asik_1
      availability: >-
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {{ my_json.power_consumption is defined }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {{ my_json.power_consumption | float(0) /1000}}

    • name: state_asik_1
      unique_id: state_asik_1
      unit_of_measurement: ‘%’
      device_class: power_factor
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% set my_summ = my_json.chains.0.chip_statuses.orange * 10 + my_json.chains.0.chip_statuses.red * 30 + my_json.chains.1.chip_statuses.orange * 10 + my_json.chains.1.chip_statuses.red * 30 + my_json.chains.2.chip_statuses.orange * 10 + my_json.chains.2.chip_statuses.red * 30 %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) or my_summ > 100 -%}
      0
      {%- else %}
      {{ 100 -my_summ }}
      {% endif %}

    • name: fan1_asik_1
      unique_id: fan1_asik_1
      unit_of_measurement: ‘RPM’

      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘binary_sensor.asik_1_is_available’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) -%}
      0
      {%- else %}
      {{ my_json.cooling.fans.0.rpm |int }}
      {% endif %}

    • name: fan2_asik_1
      unique_id: fan2_asik_1
      unit_of_measurement: ‘RPM’
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘binary_sensor.asik_1_is_available’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) -%}
      0
      {%- else %}
      {{ my_json.cooling.fans.1.rpm |int }}
      {% endif %}

    • name: fan3_asik_1
      unique_id: fan3_asik_1
      unit_of_measurement: ‘RPM’
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘binary_sensor.asik_1_is_available’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) -%}
      0
      {%- else %}
      {{ my_json.cooling.fans.2.rpm |int }}
      {% endif %}

    • name: fan4_asik_1
      unique_id: fan4_asik_1
      unit_of_measurement: ‘RPM’
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘binary_sensor.asik_1_is_available’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if my_json == ‘unknown’ or not ( states(‘binary_sensor.asik_1_is_available’) == ‘on’) -%}
      0
      {%- else %}
      {{ my_json.cooling.fans.3.rpm |int }}
      {% endif %}

    • name: miner_state_time_asik_1
      unique_id: miner_state_time_asik_1
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% set uptime = my_json.miner_status.miner_state_time | int %}
      {% if uptime == ‘unknown’ -%}
      ‘unknown’
      {%- else %}
      {% set minutes = (( uptime % 3600) / 60) | int %}
      {% set hours = ((uptime % 86400) / 3600) | int %}
      {% set days = (uptime / 86400) | int %}
      {% if uptime < 1 %}
      Меньше минуты
      {% else %}
      {% if days > 0 %}
      {{ days }} д.
      {% endif %}
      {% if hours > 0 %}
      {% if days > 0 %}
      {{ ’ ’ }}
      {% endif %}
      {{ hours }} ч.
      {% endif %}
      {% if minutes > 0 %}
      {% if days > 0 or hours > 0 %}
      {{ ’ ’ }}
      {% endif %}
      {{ minutes }} мин.
      {% endif %}
      {% endif %}
      {% endif %}

  • binary_sensor:
    • name: miner_state_asik_1
      unique_id: miner_state_asik_1
      availability: >-
      {{ states(‘sensor.miner_asik_1’) not in [‘none’, ‘unknown’, ‘unavailable’]
      and states(‘binary_sensor.asik_1_is_available’) not in [‘none’, ‘unknown’, ‘unavailable’] }}
      state: >
      {% set my_json = state_attr(‘sensor.miner_asik_1’, ‘miner’) %}
      {% if my_json == ‘unknown’ or ( not is_state(‘binary_sensor.asik_1_is_available’, ‘on’) ) -%}
      ‘off’
      {%- else %}
      {% set uptime = my_json.miner_status.miner_state_time | int %}
      {% set minutes = uptime / 60 | int %}
      {% if minutes < 2 %}
      ‘off’
      {% else %}
      {% if (my_json.miner_status.miner_state ==‘mining’ or my_json.miner_status.miner_state ==‘auto-tuning’) %}
      {{ 1==1 }}
      {% else %}
      ‘off’
      {% endif %}
      {% endif %}
      {% endif %}

Hello.
I see you are trying to connect to the Braiins OS API here.
I would like to connect to the Braiins poll API though. I have found the instructions on their site, but I am unable to configure the query and in hhtp request correctly. It does download some data, but not any about the state of the woreker.
Does anyone have any experience ?

Thanks

@mannebk running fine on L7 now wanting to implement a few sensors also on Z15 which is quite older and naive.

when i run the script in the terminal i get:

image

what can i do to address this issue ?

here below the printout i get from the raw

hei mate, what are you up to ?

Here is a HA integration that work for many Antminers, I have been using it for months and it has been working good for me: GitHub - Schnitzel/hass-miner: Controll your Bitcoin miner from Home Assistant

I was wondering if you have any strategies in regards to how often you change power limit and power off/on your miners? Considering it hurts mining consistency and possibly extra wear on the miner from stopping/starting multiple times rather than just running continuously.

I run miners from multiple locations on the same user in the same pool, so my rate is various, but never zero.

I also stack switching power. I also have a location where the grid has the option to shut down the whole location if they are kind of short on electrons :slight_smile:

So before switching power I check those machines are in fact currently online.edit: I just ping the miner, if it comes back I regard it online.

And then I never switch more than one at a time.

I currently use the integration from Schnitzel, the hass-miner