Send SSH command zu another pi

Hi,

I run plantgateway to control my miflora sensors on a pi zero.

When I restart my HA the values of my plants are not shown until another mqtt topic is pushed by the plantgateway.

Manually it is possible to push this data on demand by doing this:

  1. ssh [email protected]
  2. password
  3. cd /home/pi
  4. plantgateway

It would be great to send these commands on every ha start up.

I know that this should be possible with:

but I don’t know how to do it.

The usual way of doing this is to have your plantgateway publish its message with the retain flag set. The broker will then save the message and send it whenever a client subscribes to the topic, such as when HA restarts.

The last I heard, the embedded broker does not support this, so you must be using mosquitto or another external broker that does.

1 Like

I use mosquitto so this shouldn’t be the problem.

Don’t know how to set the retain flag in plantgateway.

EDIT:
I opened a new issue at github. Here: How to set retain flag · Issue #28 · ChristianKuehnel/plantgateway · GitHub

It looks to me as if it already is at plantgw.py line 193

 self.mqtt_client.publish(prefix, json_payload, qos=1, retain=True)

If you connect using another client, you can see if mosquitto has stored the value correctly (it may not be configured with a database). I generally do that with

mosquitto_sub -t "#" -v

You may need to add host, username and password parameters.

This will print out all message topics and the values that have been retained in the broker’s database.

Also, if you can paste the mosquitto configuration file you are using, that will say if it has the database set up.

I have hass.io running and added mosquitto in the add-on section.

Is it possible to do that in hassio?
mosquitto_sub -t "#" -v

This is my config (addon section)

{
  "logins": [
    {
      "username": "myuser",
      "password": "mypw"
    }
  ],
  "anonymous": false,
  "customize": {
    "active": false,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

I use mqttbox (mac appstore app) to troubleshot mqtt issues.

It looks llike you are right the retain flag should be set.
When I subscribe to a plant topic I get the last values. See picture

So the problem might be my configuration in ha, because the mosquitto obviously had the data stored.

This is one example of my sensors:

sensor:
    - platform: mqtt
      name: "Limette Temperatur"
      state_topic: "plantgateway/Limette/"
      value_template: '{{ value_json["temperature"] }}'
      unit_of_measurement: "°C"
      force_update: true

in plants.yaml

Limette:
  sensors:
    moisture: sensor.limette_bodenfeuchte
    battery: sensor.limette_batterie
    temperature: sensor.limette_temperatur
    conductivity: sensor.limette_fruchtbarkeit
    brightness: sensor.limette_helligkeit
  min_moisture: 15
  max_moisture: 60
  min_battery: 20
  min_conductivity: 200

Looks like this after a reboot

I’m not too sure how hassio works, as I don’t use it, but when you restart HA, does the broker restart as well?

Its just that I notice your mosquitto configuration does not set up a file to store retained messages, so if the broker restarts, it will have lost all its retained messages.

I can’t see any other problems with your configuration.

I tried that now. Even after a reboot I can get the last value using mqttbox. I don’t know if mosquitto also reboots (don’t think so), but either it does or not, the data is still here after the reboot. However, it still does not show up in the plant section.

While writing this I came up with the idea to look at the different sensors that are used by the plant component. So for example I can see the value of sensor.limette_temperatur in ha (after reboot). And it gets updated right after the reboot.

Limette:
  sensors:
    moisture: sensor.limette_bodenfeuchte
    battery: sensor.limette_batterie
    temperature: sensor.limette_temperatur
    conductivity: sensor.limette_fruchtbarkeit
    brightness: sensor.limette_helligkeit
  min_moisture: 15
  max_moisture: 60
  min_battery: 20
  min_conductivity: 200

The values are there even after the reboot, so I think there is a problem with the plant component, that does not reload the values.

I opened a new issue here, I think this is an issue of the plant component.