J’ai trouvé la solution en passant par un input_boolean
que je bascule par les scripts allumer_et_connecter_ender_3
à on
ou deconnecte_et_eteindre_ender_3
pour off
:
code des scripts
allumer_et_connecter_ender_3:
alias: Allumer et connecter Ender 3
sequence:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.nous_prise_mesure_ender_3
- delay:
hours: 0
minutes: 0
seconds: 20
milliseconds: 0
- action: rest_command.octoprint_connect
metadata: {}
data: {}
- action: input_boolean.turn_on
target:
entity_id: input_boolean.3dprinter_power_status
data: {}
description: ''
icon: mdi:connection
deconnecte_et_eteindre_ender_3:
alias: Déconnecté et éteindre Ender 3
sequence:
- action: rest_command.octoprint_disconnect
metadata: {}
data: {}
- delay:
hours: 0
minutes: 0
seconds: 20
milliseconds: 0
- action: switch.turn_off
target:
entity_id:
- switch.nous_prise_mesure_ender_3
data: {}
- action: input_boolean.turn_off
target:
entity_id:
- input_boolean.3dprinter_power_status
data: {}
description: ''
icon: mdi:connection
l'input boolean
#
# Input définissant l'état de l'imprimante 3D
#
3dprinter_power_status:
name: Etat de l'imprimante 3D
initial: off
le switch
#
# Switch pour allumer/éteindre l'imprimante 3D
# https://www.home-assistant.io/integrations/switch.template/
#
platform: template
switches:
3dprinter:
unique_id: switch_3dprinter
value_template: "{% if is_state('input_boolean.3dprinter_power_status', 'on') %}on{% else %}off{% endif %}"
turn_on:
service: script.allumer_et_connecter_ender_3
turn_off:
service: script.deconnecte_et_eteindre_ender_3
la carte
views:
- icon: mdi:printer-3d
path: 3dprinter
type: sections
sections:
- type: grid
cards:
- type: horizontal-stack
cards:
- type: custom:threedy-card
base_entity: sensor.octoprint
name: Ender 3 v2
printer_type: I3
monitored:
- Status
- ETA
- Elapsed
- Remaining
- Hotend
- Bed
Status:
entity: sensor.octoprint_print_status
Hotend:
entity: sensor.octoprint_tool_0_temperature
Bed:
entity: sensor.octoprint_bed_temperature
Progress:
entity: sensor.octoprint_print_progress
Elapsed:
entity: sensor.octoprint_print_progress
attribute: printTime
Remaining:
entity: sensor.octoprint_mqtt_print_progress
attribute: printTimeLeft
- type: horizontal-stack
cards:
- type: custom:mushroom-entity-card
entity: input_boolean.octo_controls
tap_action:
action: toggle
icon_color: indigo
name: Control
secondary_info: none
- type: horizontal-stack
cards:
- type: custom:mushroom-entity-card
entity: input_boolean.octoprint_webcam
name: Webcam
tap_action:
action: toggle
secondary_info: none
- type: custom:mushroom-entity-card
entity: input_boolean.octo_info
name: Info
tap_action:
action: toggle
secondary_info: none
- type: conditional
conditions:
- entity: input_boolean.octo_controls
state: 'on'
card:
type: custom:mushroom-title-card
title: Controls
- type: conditional
conditions:
- entity: input_boolean.octo_controls
state: 'on'
card:
type: horizontal-stack
cards:
- type: horizontal-stack
cards:
- type: custom:mushroom-template-card
primary: >-
{% if is_state('switch.nous_prise_mesure_ender_3', 'on')
%}
Allumé
{% else %}
Eteint
{% endif %}
secondary: >-
{% if is_state('binary_sensor.octoprint_connected',
'on') %}
Connectée
{% else %}
Deconnectée
{% endif %}
icon: >-
{% if is_state('switch.nous_prise_mesure_ender_3', 'on')
and is_state('binary_sensor.octoprint_connected', 'on')
%}
mdi:power-on
{% elif is_state('switch.nous_prise_mesure_ender_3',
'off') and is_state('binary_sensor.octoprint_connected',
'off') %}
mdi:power-off
{% else %}
mdi:power-cycle
{% endif %}
icon_color: >-
{% if is_state('switch.nous_prise_mesure_ender_3', 'on')
and is_state('binary_sensor.octoprint_connected', 'on')
%}
green
{% elif is_state('switch.nous_prise_mesure_ender_3',
'off') and is_state('binary_sensor.octoprint_connected',
'off') %}
grey
{% else %}
orange
{% endif %}
tap_action:
action: perform-action
perform_action: switch.toggle
target:
entity_id: switch.3dprinter
- type: custom:mushroom-template-card
primary: Leds enceinte
secondary: |-
{% if is_state('switch.lidl_prise_bureau','on') %}
allumées
{% else %}
éteintes
{% endif %}
icon: mdi:light-flood-down
tap_action:
action: perform-action
perform_action: switch.toggle
target:
entity_id: switch.lidl_prise_bureau
icon_color: |-
{% if is_state('switch.lidl_prise_bureau','on') %}
green
{% else %}
grey
{% endif %}
Et ça fonctionne nickel, lors du clic sur :
Le bouton passe à « Allumée » et « déconnectée » :
Puis à « Allumée » et « connectée » :
Et je vois bien la connexion de l’imprimante sur Octoprint.
Et inversement, si je reclique sur le bouton, je passe à « Allumée » et « déconnectée » puis « Eteinte » et « Déconnectée » et je vois la déconnexion sur Octoprint.