Skip to content

Instantly share code, notes, and snippets.

@jbrazio
Last active May 17, 2024 10:55
Show Gist options
  • Save jbrazio/244dc580843907a4cfbd9e774bc9a138 to your computer and use it in GitHub Desktop.
Save jbrazio/244dc580843907a4cfbd9e774bc9a138 to your computer and use it in GitHub Desktop.
Home Assistant and Freqtrade

Home Assistant and Freqtrade

This gist contains all the configuration files you will need to have something like this on your HASS dashboard.

Preview

This is an example configuration to get you started. It assumes you use a split configuration in Home Assistant. I like to have a entities folder on root and then inside I have a folder for each entity type (binary, cover, light, switch, sensor, etc) but you may adapt to your own configuration style.

In the configuration.yaml file make sure that you have something like this:

rest_command: !include restcmd.yaml
rest: !include_dir_merge_list entities/rest/
sensor: !include_dir_merge_list entities/sensor/

Start by adding the secrets to your secrets.yaml file which shall be next to your configuration.yaml file. Then create, also on the root directory, a new restcmd.yaml file and copy paste the contents from the gist bellow.

Assuming you have the top level entities directory, create two additional subdirectories rest and sensor if they are not already there, then copy entities/rest/freqtrade.b1.yaml and entities/sensor/variables.yaml.

In the end it may look something like this:

.
├── automations.yaml
├── blueprints
├── configuration.yaml
├── custom_components
├── customize.yaml
├── deps
├── entities
│   ├── binary
│   ├── cover
│   ├── light
│   ├── rest
│   │   ├── freqtrade-b1.yaml
│   │   └── freqtrade-b2.yaml
│   ├── sensor
│   │   └── variables.yaml
│   └── switch
├── groups.yaml
├── home-assistant.log
├── home-assistant_v2.db
├── image
├── restcmd.yaml
├── scenes.yaml
├── scripts.yaml
├── secrets.yaml
├── tts
├── www
└── zigbee.db

All the files in lovelace should be manually added using the Show Code Editor feature on the Home Assistant GUI.

##
# Freqtrade bot #1
# This file specifies the available REST sensors
# In order to have multiple bots, just copy this file to a new one and replace all instances of
# 'freqtrade_b1' with 'freqtrade_bX'. Remember that you will need to edit your secrets file and the
# URL sensor for the new bot.
##
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 30
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/balance"
sensor:
- name: freqtrade_b1_balance
value_template: "{{ value_json.value | float(0) | round(2) }}"
unit_of_measurement: EUR
json_attributes:
- "currencies"
- "total"
- "symbol"
- "value"
- "stake"
- "note"
- "starting_capital"
- "starting_capital_ratio"
- "starting_capital_pct"
- "starting_capital_fiat"
- "starting_capital_fiat_ratio"
- "starting_capital_fiat_pct"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 30
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/count"
sensor:
- name: freqtrade_b1_status
value_template: "{{ value_json.total_stake }}"
unit_of_measurement: EUR
json_attributes:
- "current"
- "max"
- "total_stake"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 30
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/profit"
sensor:
- name: freqtrade_b1_profit
value_template: "{{ value_json.profit_all_fiat | float | round(2) }}"
unit_of_measurement: EUR
json_attributes:
- "avg_duration"
- "closed_trade_count"
- "first_trade_date"
- "first_trade_timestamp"
- "latest_trade_date"
- "latest_trade_timestamp"
- "losing_trades"
- "profit_all_fiat"
- "profit_closed_fiat"
- "trade_count"
- "winning_trades"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 60
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/show_config"
sensor:
- name: freqtrade_b1_show_config
value_template: "{{ value_json.state }}"
json_attributes:
- "dry_run"
- "stake_currency"
- "stake_amount"
- "available_capital"
- "stake_currency_decimals"
- "max_open_trades"
- "minimal_roi"
- "stoploss"
- "trailing_stop"
- "trailing_stop_positive"
- "trailing_stop_positive_offset"
- "trailing_only_offset_is_reached"
- "use_custom_stoploss"
- "timeframe"
- "timeframe_ms"
- "timeframe_min"
- "exchange"
- "strategy"
- "forcebuy_enabled"
- "ask_strategy"
- "bid_strategy"
- "bot_name"
- "state"
- "runmode"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 10
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/status"
sensor:
- name: freqtrade_b1_slot_1
value_template: "{{ value_json[0].profit_fiat | float(0) | round(2) }}"
json_attributes_path: "$.[0]."
unit_of_measurement: EUR
json_attributes:
- "amount"
- "amount_requested"
- "buy_tag"
- "current_rate"
- "max_rate"
- "min_rate"
- "open_date"
- "open_rate"
- "pair"
- "profit_fiat"
- "profit_pct"
- "sell_reason"
- "stake_amount"
- "strategy"
- "trade_id"
- name: freqtrade_b1_slot_2
value_template: "{{ value_json[1].profit_fiat | float(0) | round(2) }}"
json_attributes_path: "$.[1]."
unit_of_measurement: EUR
json_attributes:
- "amount"
- "amount_requested"
- "buy_tag"
- "current_rate"
- "max_rate"
- "min_rate"
- "open_date"
- "open_rate"
- "pair"
- "profit_fiat"
- "profit_pct"
- "sell_reason"
- "stake_amount"
- "strategy"
- "trade_id"
- name: freqtrade_b1_slot_3
value_template: "{{ value_json[2].profit_fiat | float(0) | round(2) }}"
json_attributes_path: "$.[2]."
unit_of_measurement: EUR
json_attributes:
- "amount"
- "amount_requested"
- "buy_tag"
- "current_rate"
- "max_rate"
- "min_rate"
- "open_date"
- "open_rate"
- "pair"
- "profit_fiat"
- "profit_pct"
- "sell_reason"
- "stake_amount"
- "strategy"
- "trade_id"
- name: freqtrade_b1_slot_4
value_template: "{{ value_json[3].profit_fiat | float(0) | round(2) }}"
json_attributes_path: "$.[3]."
unit_of_measurement: EUR
json_attributes:
- "amount"
- "amount_requested"
- "buy_tag"
- "current_rate"
- "max_rate"
- "min_rate"
- "open_date"
- "open_rate"
- "pair"
- "profit_fiat"
- "profit_pct"
- "sell_reason"
- "stake_amount"
- "strategy"
- "trade_id"
- name: freqtrade_b1_slot_5
value_template: "{{ value_json[4].profit_fiat | float(0) | round(2) }}"
json_attributes_path: "$.[4]."
unit_of_measurement: EUR
json_attributes:
- "amount"
- "amount_requested"
- "buy_tag"
- "current_rate"
- "max_rate"
- "min_rate"
- "open_date"
- "open_rate"
- "pair"
- "profit_fiat"
- "profit_pct"
- "sell_reason"
- "stake_amount"
- "strategy"
- "trade_id"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 10
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/trades"
sensor:
- name: freqtrade_b1_trades_1
value_template: "{{ value_json.trades[value_json.trades_count-1].pair }}"
json_attributes_path: "$.trades[(@.length-1)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_2
value_template: "{{ value_json.trades[value_json.trades_count-2].pair }}"
json_attributes_path: "$.trades[(@.length-2)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_3
value_template: "{{ value_json.trades[value_json.trades_count-3].pair }}"
json_attributes_path: "$.trades[(@.length-3)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_4
value_template: "{{ value_json.trades[value_json.trades_count-4].pair }}"
json_attributes_path: "$.trades[(@.length-4)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_5
value_template: "{{ value_json.trades[value_json.trades_count-5].pair }}"
json_attributes_path: "$.trades[(@.length-5)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_6
value_template: "{{ value_json.trades[value_json.trades_count-6].pair }}"
json_attributes_path: "$.trades[(@.length-6)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_7
value_template: "{{ value_json.trades[value_json.trades_count-7].pair }}"
json_attributes_path: "$.trades[(@.length-7)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_8
value_template: "{{ value_json.trades[value_json.trades_count-8].pair }}"
json_attributes_path: "$.trades[(@.length-8)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_9
value_template: "{{ value_json.trades[value_json.trades_count-9].pair }}"
json_attributes_path: "$.trades[(@.length-9)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- name: freqtrade_b1_trades_10
value_template: "{{ value_json.trades[value_json.trades_count-10].pair }}"
json_attributes_path: "$.trades[(@.length-10)]."
json_attributes:
- "trade_id"
- "pair"
- "is_open"
- "amount"
- "amount_requested"
- "stake_amount"
- "buy_tag"
- "open_date"
- "open_rate"
- "close_date"
- "close_rate"
- "profit_pct"
- "profit_abs"
- "sell_reason"
- authentication: basic
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
scan_interval: 120
resource_template: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/daily"
sensor:
- name: freqtrade_b1_daily_1
value_template: "{{ value_json.data[0].trade_count }}"
json_attributes_path: "$.data[0]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_2
value_template: "{{ value_json.data[1].trade_count }}"
json_attributes_path: "$.data[1]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_3
value_template: "{{ value_json.data[2].trade_count }}"
json_attributes_path: "$.data[2]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_4
value_template: "{{ value_json.data[3].trade_count }}"
json_attributes_path: "$.data[3]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_5
value_template: "{{ value_json.data[4].trade_count }}"
json_attributes_path: "$.data[4]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_6
value_template: "{{ value_json.data[5].trade_count }}"
json_attributes_path: "$.data[5]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
- name: freqtrade_b1_daily_7
value_template: "{{ value_json.data[6].trade_count }}"
json_attributes_path: "$.data[6]."
json_attributes:
- "date"
- "abs_profit"
- "fiat_value"
- "trade_count"
##
# Freqtrade bot #1
# This is an hack for the common URL for all the API calls. HA does not support user defined vars
# without a HACS extension.. how stupid is this ?
##
- platform: template
sensors:
freqtrade_b1_url:
value_template: !secret freqtrade_b1_api
alias: Freqtrade - Close trade
description: 'Sends a notification when a trade is closed'
trigger:
- platform: state
entity_id: sensor.freqtrade_b1_slot_1
to: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_2
to: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_3
to: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_4
to: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
condition: []
action:
- service: notify.YOUR_MOBILE_APP_PHONE_HERE
data:
title: '{{ trigger.from_state.attributes.friendly_name }}'
message: >-
Closed an open trade for {{ trigger.from_state.attributes.pair }} in the
amount of {{ trigger.from_state.attributes.stake_amount | float(3) |
round(3) }}€ with a profit of {{
trigger.from_state.attributes.profit_fiat | float(0) | round(3) }}€ ({{
trigger.from_state.attributes.profit_pct | float(0) | round(3) }}%).
data:
group: freqtrade
tag: freqtrade-trade-close
mode: single
alias: Freqtrade - Open trade
description: 'Send a notification when a new trade is open'
trigger:
- platform: state
entity_id: sensor.freqtrade_b1_slot_1
from: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_2
from: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_3
from: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
- platform: state
entity_id: sensor.freqtrade_b1_slot_4
from: unknown
for:
hours: 0
minutes: 0
seconds: 60
milliseconds: 0
condition: []
action:
- service: notify.YOUR_MOBILE_APP_PHONE_HERE
data:
title: '{{ trigger.to_state.attributes.friendly_name }}'
message: >-
Open trade for {{ trigger.to_state.attributes.pair }} in the amount of
{{ trigger.to_state.attributes.stake_amount | float(0) | round(3) }}€
({{ trigger.to_state.attributes.open_rate | float(0) | round(4) }}).
data:
group: freqtrade
tag: freqtrade-trade-open
mode: single
#
# You will need template-entity-row, install it using HACS
#
type: entities
entities:
- type: custom:template-entity-row
icon: mdi:numeric-1
name: '{{ state_attr(''sensor.freqtrade_b1_daily_1'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_1', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_1',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_1', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-2
name: '{{ state_attr(''sensor.freqtrade_b1_daily_2'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_2', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_2',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_2', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-3
name: '{{ state_attr(''sensor.freqtrade_b1_daily_3'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_3', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_3',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_3', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-4
name: '{{ state_attr(''sensor.freqtrade_b1_daily_4'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_4', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_4',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_4', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-5
name: '{{ state_attr(''sensor.freqtrade_b1_daily_5'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_5', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_5',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_5', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-6
name: '{{ state_attr(''sensor.freqtrade_b1_daily_6'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_6', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_6',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_6', 'trade_count')
}}
- type: custom:template-entity-row
icon: mdi:numeric-7
name: '{{ state_attr(''sensor.freqtrade_b1_daily_7'', ''date'') }}'
state: >-
{{ state_attr('sensor.freqtrade_b1_daily_7', 'fiat_value') | float(0) |
round(3) }} € {% if state_attr('sensor.freqtrade_b1_daily_7',
'fiat_value') | float(0) > 0 %}
🟢 {% else %} 🟥 {%- endif -%}
secondary: >-
Total trades: {{ state_attr('sensor.freqtrade_b1_daily_7', 'trade_count')
}}
#
# You will need template-entity-row, install it using HACS
#
type: vertical-stack
cards:
- type: sensor
entity: sensor.freqtrade_b1_balance
detail: 1
graph: line
name: Balance
icon: mdi:chart-pie
unit: €
hours_to_show: 12
- type: entities
entities:
- type: buttons
entities:
- type: custom:template-entity-row
icon: mdi:play
tap_action:
action: call-service
service: rest_command.freqtrade_b1_start
- type: custom:template-entity-row
icon: mdi:pause
tap_action:
action: call-service
service: rest_command.freqtrade_b1_pause
- type: custom:template-entity-row
icon: mdi:stop
tap_action:
action: call-service
service: rest_command.freqtrade_b1_stop
confirmation:
text: Stop the bot ?
- type: custom:template-entity-row
icon: mdi:reload
tap_action:
action: call-service
service: rest_command.freqtrade_b1_reload
confirmation:
text: Reload configuration ?
- type: entities
entities:
- type: section
label: Overview
- type: custom:template-entity-row
name: State
icon: mdi:pulse
state: >-
{{ state_attr('sensor.freqtrade_b1_show_config', 'state') | capitalize
}} ({{ state_attr('sensor.freqtrade_b1_show_config', 'runmode') |
capitalize}})
- type: custom:template-entity-row
name: Strategy
icon: mdi:strategy
state: >-
{{ state_attr('sensor.freqtrade_b1_show_config', 'strategy') }} ({{
state_attr('sensor.freqtrade_b1_show_config', 'timeframe') }})
- type: custom:template-entity-row
name: Stake
icon: mdi:wallet
state: >-
{{ state_attr('sensor.freqtrade_b1_status', 'total_stake') | round(2)
}}€
- type: custom:template-entity-row
name: Profit
icon: mdi:finance
state: >-
{{ state_attr('sensor.freqtrade_b1_profit', 'profit_closed_fiat') |
round(2) }}€
secondary: >-
{{state_attr('sensor.freqtrade_b1_profit', 'profit_all_fiat') |
round(2)}}€ currently
- type: custom:template-entity-row
name: Performance
icon: mdi:thumbs-up-down
state: >-
{{ state_attr('sensor.freqtrade_b1_profit',
'winning_trades')}}:{{state_attr('sensor.freqtrade_b1_profit',
'losing_trades') }}
secondary: >-
{{state_attr('sensor.freqtrade_b1_profit', 'trade_count') }} total
trades
- type: section
label: Trades
- type: custom:template-entity-row
name: Running trades
icon: mdi:podium
state: >-
{{ state_attr('sensor.freqtrade_b1_status', 'current')}} / {{
state_attr('sensor.freqtrade_b1_status', 'max')}}
secondary: >-
Average duration {{ state_attr('sensor.freqtrade_b1_profit',
'avg_duration') }}
- type: custom:template-entity-row
name: Latest trade
icon: mdi:clock
state: '{{ state_attr(''sensor.freqtrade_b1_profit'', ''latest_trade_date'')}}'
#
# You will need mini-graph-card, multiple-entity-row and template-entity-row install it using HACS
#
type: vertical-stack
cards:
- type: conditional
conditions:
- entity: sensor.freqtrade_b1_slot_1
state_not: unknown
card:
type: entities
entities:
- type: custom:mini-graph-card
name: Slot 1
hours_to_show: 24
points_per_hour: 4
smoothing: false
line_width: 2
update_interval: 60
hour24: true
decimals: 3
show:
icon: false
points: false
entities:
- entity: sensor.freqtrade_b1_slot_1
unit: €
show_indicator: false
- type: section
- entity: sensor.freqtrade_b1_slot_1
type: custom:multiple-entity-row
attribute: pair
name: Pair
secondary_info:
entity: sensor.freqtrade_b1_slot_1
attribute: open_date
name: false
format: relative
icon: mdi:yin-yang
entities:
- icon: mdi:cash-minus
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_forcesell
service_data:
slot: '1'
confirmation:
text: Force sell ?
- icon: mdi:cash-remove
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_delete
service_data:
slot: '1'
confirmation:
text: Delete ?
- type: custom:template-entity-row
name: Amount
icon: mdi:cash
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_1', 'stake_amount') |
float(0) | round(2) }}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_1', 'amount') | float(0)}}
/ {{ state_attr('sensor.freqtrade_b1_slot_1', 'amount_requested') |
float(0)}}
- type: custom:template-entity-row
name: Performance
icon: mdi:poll
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_1', 'profit_fiat') |
float(0) | round(3)}}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_1', 'profit_pct') |
float(0)}}%
- type: custom:template-entity-row
name: Current Rate
icon: mdi:update
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_1', 'current_rate') |
float(0)}}
secondary: >-
min: {{ state_attr('sensor.freqtrade_b1_slot_1', 'min_rate') |
float(0) | round(5) }}, max: {{
state_attr('sensor.freqtrade_b1_slot_1', 'max_rate') | float(0) |
round(5) }}, open: {{ state_attr('sensor.freqtrade_b1_slot_1',
'open_rate') | float(0) | round(5) }}
- type: conditional
conditions:
- entity: sensor.freqtrade_b1_slot_2
state_not: unknown
card:
type: entities
entities:
- type: custom:mini-graph-card
name: Slot 2
hours_to_show: 24
points_per_hour: 4
smoothing: false
line_width: 2
update_interval: 60
hour24: true
decimals: 3
show:
icon: false
points: false
entities:
- entity: sensor.freqtrade_b1_slot_2
unit: €
show_indicator: false
- type: section
- entity: sensor.freqtrade_b1_slot_2
type: custom:multiple-entity-row
attribute: pair
name: Pair
secondary_info:
entity: sensor.freqtrade_b1_slot_2
attribute: open_date
name: false
format: relative
icon: mdi:yin-yang
entities:
- icon: mdi:cash-minus
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_forcesell
service_data:
slot: '2'
confirmation:
text: Force sell ?
- icon: mdi:cash-remove
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_delete
service_data:
slot: '2'
confirmation:
text: Delete ?
- type: custom:template-entity-row
name: Amount
icon: mdi:cash
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_2', 'stake_amount') |
float(0) | round(2) }}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_2', 'amount') | float(0)}}
/ {{ state_attr('sensor.freqtrade_b1_slot_2', 'amount_requested') |
float(0)}}
- type: custom:template-entity-row
name: Performance
icon: mdi:poll
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_2', 'profit_fiat') |
float(0) | round(3)}}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_2', 'profit_pct') |
float(0)}}%
- type: custom:template-entity-row
name: Current Rate
icon: mdi:update
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_2', 'current_rate') |
float(0)}}
secondary: >-
min: {{ state_attr('sensor.freqtrade_b1_slot_2', 'min_rate') |
float(0) | round(5) }}, max: {{
state_attr('sensor.freqtrade_b1_slot_2', 'max_rate') | float(0) |
round(5) }}, open: {{ state_attr('sensor.freqtrade_b1_slot_2',
'open_rate') | float(0) | round(5) }}
- type: conditional
conditions:
- entity: sensor.freqtrade_b1_slot_3
state_not: unknown
card:
type: entities
entities:
- type: custom:mini-graph-card
name: Slot 3
hours_to_show: 24
points_per_hour: 4
smoothing: false
line_width: 2
update_interval: 60
hour24: true
decimals: 3
show:
icon: false
points: false
entities:
- entity: sensor.freqtrade_b1_slot_3
unit: €
show_indicator: false
- type: section
- entity: sensor.freqtrade_b1_slot_3
type: custom:multiple-entity-row
attribute: pair
name: Pair
secondary_info:
entity: sensor.freqtrade_b1_slot_3
attribute: open_date
name: false
format: relative
icon: mdi:yin-yang
entities:
- icon: mdi:cash-minus
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_forcesell
service_data:
slot: '3'
confirmation:
text: Force sell ?
- icon: mdi:cash-remove
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_delete
service_data:
slot: '3'
confirmation:
text: Delete ?
- type: custom:template-entity-row
name: Amount
icon: mdi:cash
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_3', 'stake_amount') |
float(0) | round(2) }}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_3', 'amount') | float(0)}}
/ {{ state_attr('sensor.freqtrade_b1_slot_3', 'amount_requested') |
float(0)}}
- type: custom:template-entity-row
name: Performance
icon: mdi:poll
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_3', 'profit_fiat') |
float(0) | round(3)}}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_3', 'profit_pct') |
float(0)}}%
- type: custom:template-entity-row
name: Current Rate
icon: mdi:update
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_3', 'current_rate') |
float(0)}}
secondary: >-
min: {{ state_attr('sensor.freqtrade_b1_slot_3', 'min_rate') |
float(0) | round(5) }}, max: {{
state_attr('sensor.freqtrade_b1_slot_3', 'max_rate') | float(0) |
round(5) }}, open: {{ state_attr('sensor.freqtrade_b1_slot_3',
'open_rate') | float(0) | round(5) }}
- type: conditional
conditions:
- entity: sensor.freqtrade_b1_slot_4
state_not: unknown
card:
type: entities
entities:
- type: custom:mini-graph-card
name: Slot 4
hours_to_show: 24
points_per_hour: 4
smoothing: false
line_width: 2
update_interval: 60
hour24: true
decimals: 3
show:
icon: false
points: false
entities:
- entity: sensor.freqtrade_b1_slot_4
unit: €
show_indicator: false
- type: section
- entity: sensor.freqtrade_b1_slot_4
type: custom:multiple-entity-row
attribute: pair
name: Pair
secondary_info:
entity: sensor.freqtrade_b1_slot_4
attribute: open_date
name: false
format: relative
icon: mdi:yin-yang
entities:
- icon: mdi:cash-minus
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_forcesell
service_data:
slot: '4'
confirmation:
text: Force sell ?
- icon: mdi:cash-remove
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_delete
service_data:
slot: '4'
confirmation:
text: Delete ?
- type: custom:template-entity-row
name: Amount
icon: mdi:cash
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_4', 'stake_amount') |
float(0) | round(2) }}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_4', 'amount') | float(0)}}
/ {{ state_attr('sensor.freqtrade_b1_slot_4', 'amount_requested') |
float(0)}}
- type: custom:template-entity-row
name: Performance
icon: mdi:poll
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_4', 'profit_fiat') |
float(0) | round(3)}}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_4', 'profit_pct') |
float(0)}}%
- type: custom:template-entity-row
name: Current Rate
icon: mdi:update
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_4', 'current_rate') |
float(0)}}
secondary: >-
min: {{ state_attr('sensor.freqtrade_b1_slot_4', 'min_rate') |
float(0) | round(5) }}, max: {{
state_attr('sensor.freqtrade_b1_slot_4', 'max_rate') | float(0) |
round(5) }}, open: {{ state_attr('sensor.freqtrade_b1_slot_4',
'open_rate') | float(0) | round(5) }}
- type: conditional
conditions:
- entity: sensor.freqtrade_b1_slot_5
state_not: unknown
card:
type: entities
entities:
- type: custom:mini-graph-card
name: Slot 5
hours_to_show: 24
points_per_hour: 4
smoothing: false
line_width: 2
update_interval: 60
hour24: true
decimals: 3
show:
icon: false
points: false
entities:
- entity: sensor.freqtrade_b1_slot_5
unit: €
show_indicator: false
- type: section
- entity: sensor.freqtrade_b1_slot_5
type: custom:multiple-entity-row
attribute: pair
name: Pair
secondary_info:
entity: sensor.freqtrade_b1_slot_5
attribute: open_date
name: false
format: relative
icon: mdi:yin-yang
entities:
- icon: mdi:cash-minus
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_forcesell
service_data:
slot: '5'
confirmation:
text: Force sell ?
- icon: mdi:cash-remove
state_color: true
tap_action:
action: call-service
service: rest_command.freqtrade_b1_delete
service_data:
slot: '5'
confirmation:
text: Delete ?
- type: custom:template-entity-row
name: Amount
icon: mdi:cash
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_5', 'stake_amount') |
float(0) | round(2) }}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_5', 'amount') | float(0)}}
/ {{ state_attr('sensor.freqtrade_b1_slot_5', 'amount_requested') |
float(0)}}
- type: custom:template-entity-row
name: Performance
icon: mdi:poll
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_5', 'profit_fiat') |
float(0) | round(3)}}€
secondary: >-
{{ state_attr('sensor.freqtrade_b1_slot_5', 'profit_pct') |
float(0)}}%
- type: custom:template-entity-row
name: Current Rate
icon: mdi:update
state: >-
{{ state_attr('sensor.freqtrade_b1_slot_5', 'current_rate') |
float(0)}}
secondary: >-
min: {{ state_attr('sensor.freqtrade_b1_slot_5', 'min_rate') |
float(0) | round(5) }}, max: {{
state_attr('sensor.freqtrade_b1_slot_5', 'max_rate') | float(0) |
round(5) }}, open: {{ state_attr('sensor.freqtrade_b1_slot_5',
'open_rate') | float(0) | round(5) }}
##
# Freqtrade bot #1
# This file specifies the available REST commands
# In order to have multiple bots, just copy this section and replace all instances of 'freqtrade_b1'
# with 'freqtrade_bX'. Remember that you will need to edit your secrets file and the URL sensor for
# the new bot.
##
freqtrade_b1_start:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/start"
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
freqtrade_b1_pause:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/stopbuy"
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
freqtrade_b1_stop:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/stop"
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
freqtrade_b1_reload:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/reload_config"
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
freqtrade_b1_forcebuy:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/forcebuy"
content_type: 'application/json; charset=utf-8'
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
payload: '{ "pair": "{{ pair }}", "price": "{{ price }}" }'
freqtrade_b1_forcesell:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/forcesell"
content_type: 'application/json; charset=utf-8'
verify_ssl: true
method: POST
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
payload: >-
{ "tradeid": "{{ state_attr('sensor.freqtrade_b1_slot_' + slot, "trade_id") }}" }
freqtrade_b1_delete:
url: "{{ states('sensor.freqtrade_b1_url') }}/api/v1/trades/{{ state_attr('sensor.freqtrade_b1_slot_' + slot, 'trade_id') }}"
content_type: 'application/json; charset=utf-8'
verify_ssl: true
method: DELETE
username: !secret freqtrade_b1_usr
password: !secret freqtrade_b1_pwd
payload: '{ "slot": "{{ slot }}" }'
# Use this file to store secrets like usernames and passwords.
# Learn more at https://www.home-assistant.io/docs/configuration/secrets/
##
# Freqtrade bot #1
##
freqtrade_b1_usr: my_username
freqtrade_b1_pwd: super_secret_password
freqtrade_b1_api: https://one_bot.my_domain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment