STUCK: Help needed with ESPhome scripting refinement for fireplace automation

Hi there. I have build a simple script for controlling my Mertik Maxitrol GV60 controller for fireplace. I have studied the fireplace manual for a long time and was able to find out which circuit must be closed for certain functionality for the wall switch connection. I connected a 4-way relay to it with an ESP32. It’s working fine but I would like to refine my script to a more ‘professional’ version with some additional checks. I read alot on the esphome but it’s beyond my programming knowledge.

What I just can’t manage is the following:

  • I would like have a status sensor with an entry of the last chosen platform name turn_on_action
    This way I can read the current status of the fireplace in Home Assistant.

  • Because the relay’s needed to be inverted (otherwise they are all on by default) the status does not want to change to on. I use lambda for this where I look at the status of 1 switch ID. But the way I’ve done it now, the lambda IF states are not unique. I would like to make an IF statement where at least 2 id’s must match before a true can be given.

It’s my first code in esphome so if you guys can help me? That would be fantastic

esphome:
  name: openhaard
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Openhaard Fallback Hotspot"
    password: "notworking"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

switch:
  - platform: gpio
    pin: GPIO16
    id: pin0
    internal: yes
    inverted: yes
    restore_mode: ALWAYS_OFF
  - platform: gpio
    pin: GPIO17
    id: pin1
    internal: yes
    inverted: yes
    restore_mode: ALWAYS_OFF
  - platform: gpio
    pin: GPIO18
    id: pin2
    internal: yes
    inverted: yes
    restore_mode: ALWAYS_OFF
  - platform: gpio
    pin: GPIO19
    id: pin3
    internal: yes
    inverted: yes
    restore_mode: ALWAYS_OFF
    
  - platform: template
    name: "Ontsteking"
    icon: "mdi:fire"
    id: ignition
    lambda: |-
      if (id(pin0).state)  {
        return true;
      } else {
        return false;
      }
    turn_on_action:
    - switch.turn_on: pin0
    - switch.turn_on: pin1
    - switch.turn_on: pin3
    - delay: 4s
    - switch.turn_off: pin0
    - switch.turn_off: pin1
    - switch.turn_off: pin3
    
  - platform: template
    name: "Omhoog"
    icon: "mdi:inbox-arrow-up"
    id: up
    lambda: |-
      if (id(pin1).state)  {
        return true;
      } else {
        return false;
      }
    turn_on_action:
    - switch.turn_on: pin0
    - switch.turn_on: pin1
    turn_off_action:
    - switch.turn_off: pin0
    - switch.turn_off: pin1

  - platform: template
    name: "Omlaag"
    icon: "mdi:inbox-arrow-down"
    id: down
    lambda: |-
      if (id(pin3).state)  {
        return true;
      } else {
        return false;
      }
    turn_on_action:
    - switch.turn_on: pin0
    - switch.turn_on: pin3
    turn_off_action:
    - switch.turn_off: pin0
    - switch.turn_off: pin3
    
  - platform: template
    name: "Waakvlam"
    icon: "mdi:infinity"
    id: pilotflame
    lambda: |-
      if (id(pin3).state)  {
        return true;
      } else {
        return false;
      }
    turn_on_action:
    - switch.turn_on: pin0
    - switch.turn_on: pin3
    - delay: 12s
    - switch.turn_off: pin0
    - switch.turn_off: pin3
    
  - platform: template
    name: "Uit (Wintertijd)"
    icon: "mdi:radiator-off"
    id: off
    lambda: |-
      if (id(pin2).state)  {
        return true;
      } else {
        return false;
      }
    turn_on_action:
    - switch.turn_on: pin0
    - switch.turn_on: pin1
    - switch.turn_on: pin2
    - switch.turn_on: pin3
    - delay: 1s
    - switch.turn_off: pin0
    - switch.turn_off: pin1
    - switch.turn_off: pin2
    - switch.turn_off: pin3

Capture

1 Like

@ottovw can you please share how you have connected it to your panel
do you have setup 4 switches?\

Create a text sensor

# Example configuration entry
text_sensor:
  - platform: template
    name: "Template Text Sensor"
    id: template_text

Then update it’s status in each automation

# in some trigger
on_...:
  - text_sensor.template.publish:
      id: template_text
      state: "Hello World"
1 Like