Solar Powered BTC Mining Automation with HA

I just started using Home Assistant and I want to automate the power settings on my BTC mining rigs with the goal of matching mining power to PV power throughout the day. I have the SSH commands figured out for HA to control the mining power. And Solar Assistant is set up to provide the solar system information to HA. I’d like to create automation that is something like if battery charging power > 1 KW, step up mining power. And if battery discharging power >1 KW, step down mining power.

The power values I would send to the miners via SSH would be specific and have a max and min value. Towards the end of the day when the min target powers are reached and there is a significant deficit in power on the batteries, these miners will be powered down. I have been thinking the way this would work is I’d have a table of power target values and HA would step up and down along these values reacting to the battery power and halting if it reaches the max or min. I have zero experience with Jinja so obviously, I need to start learning that language. Where should I start in trying to make this automation work?

For the time being, I have several automations in place which trigger based on PV output for setting the different target powers to the miners. But this is not ideal as the actual home load can change so I need this perfected by using the charge or drain on the battery system.

Hello Brian,
Welcome to the HA Forum

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/

First rule of the Forums here is share the code you are talking about and let us know the goal. I think your goal is in there, but could use a little focus, but we don’t know what you tried to use to get there.

I found a lot more expressions in the UI so I was able to work up the idea of what I’m trying to do. See code below for a couple of step ups. The idea is every time the battery power is greater than 1000 watts, it’ll run the SSH command for the next step up on mining power and then set the entity known as power target to the next power up (300 watts higher). This is the tracker so the automation knows what the next step will be and the next time it sees 1000 watts or more, runs the actions for that particular step. This will have many other steps but I’ve only made 2 for the example. And there will be another automation which handles stepping down when battery power is losing 1000 watts or more.

My issue appears to be with the target power condition. It is not recognizing the target state as a match even though the value does match. I cannot figure out why. What am I doing wrong? Or is there a better way to handle the step ups and downs? I could use a counter but the coding would basically be the same.

alias: Target Power Up
description: “”
triggers:

  • type: power
    device_id: 3d61ff3ca04d3c7424802869752d45aa
    entity_id: 77c899ec43723e7ef696c0db4452d211
    domain: sensor
    trigger: device
    above: 1000
    for:
    hours: 0
    minutes: 2
    seconds: 0
    conditions:
  • condition: time
    after: “09:00:00”
    before: “18:00:00”
    weekday:
    • fri
    • thu
    • wed
    • tue
    • mon
      enabled: true
      actions:
  • if:
    • condition: state
      entity_id: input_number.power_target
      state: “5860”
      then:
    • action: ssh_command.exec_command
      metadata: {}
      data:
      user: dudanation
      pass: password
      command: >-
      /home/dudanation/BRAIINS/braiins-toolbox tuner target --power 6160
      ‘192.168.50.71-74’
      host: 192.168.50.68
    • action: input_number.set_value
      metadata: {}
      data:
      value: 6160
      target:
      entity_id: input_number.power_target
      else:
    • if:
      • condition: state
        entity_id: input_number.power_target
        state: “5560”
        then:
      • action: ssh_command.exec_command
        metadata: {}
        data:
        user: dudanation
        pass: password
        command: >-
        /home/dudanation/BRAIINS/braiins-toolbox tuner target --power
        5860 ‘192.168.50.71-74’
        host: 192.168.50.68
      • action: input_number.set_value
        metadata: {}
        data:
        value: 5860
        target:
        entity_id: input_number.power_target
        mode: single