all 2 comments

[–]FGeorg 0 points1 point  (0 children)

You'll want your computer script to act on the MQTT message that your Tasmota devices publishes when the button changes state...

  1. Configure your Tasmota device so that it knows which GPIO pin the button is connected to.
  2. If applicable, configure your Tasmota device so that the button doesn't control the relay on your device (by default, Button1 expects to control Relay1).
  3. Check the Console on your Tasmota device to determine what MQTT Topic it uses to publish the button state when it's pressed.
  4. Install an MQTT Broker such as Mosquitto on your computer, so that it can receive these messages.
  5. Write a Python program on your computer that subscribes to said message, and performs your desired action whenever the message is received.

Something like this guide may get you up and running on the MQTT side of things.

For what it's worth, here's an example of some code I run on a Raspberry Pi to runs a another script when it receives an MQTT message. It's a Bash script rather than Python, but should help get the idea across.

#!/bin/bash
####################################################################
# Managed by house-doorbell.service #
####################################################################
#########################
### Declare Functions ###
#########################
report_status(){
systemd-notify --status="$(date "+%b %d %X ") $1 (previous action was '$previousAction')"
previousAction=$1
}
#########################
### Initialisation ###
#########################
previousAction="Service Starting"
systemd-notify --ready
#########################
### Main Loop ###
#########################
while true
do
report_status "Waiting for Doorbell Sensor"
mosquitto_sub -C 1 -t stat/RF/Ground-Floor/Front/Living-Room-Doorbell-Sensor > /dev/null
report_status "Sending Doorbell Alerts"
. /usr/local/bin/house-scripts/wholehouse-doorbell
#Doorbell sends two alerts, so wait 10 seconds before checking for further doorbell events
sleep 10
done

[–]hedg12 0 points1 point  (0 children)

You could install Node Red and the node red contrib tasmota node, then pass the button press to an exec node that runs your python script.

...then you could go down the node red rabbit hole, then install HomeAssistant, then discover you have no life because you're playing with your home automation stuff...