hemtjanst / hallonlarm

Raspberry Pi GPIO to MQTT and Hemtjänst
https://hemtjan.st/hallonlarm
Apache License 2.0
5 stars 0 forks source link

Configuration help #2

Closed the-butterfry closed 5 years ago

the-butterfry commented 6 years ago

I'm back :) When I initially set hallonlarm up, everything was working great for the configuration I needed it for. All functions that were needed (gpioIn) were working internally on the Pi. Now i'm attempting to set pin states externally via MQTT (via another MQTT publisher) and i can't get it to work. It's obviously my .conf file which is having issues. I've gone over the similar hemtjanst documentation as well to try and find where i'm going wrong.

Is it possible to combine the gpioOut and gpioIn configuration sections into one? or do we need two separate sections in the config file. Maybe i'm asking too much, or using the IN/OUT config all wrong?

Here's what I"m trying to do.

  1. WORKING FINE - On RPi, set pin states and publish GPIO MQTT messages on state change. Achieved using gpioIn config
  2. Not working - Remote MQTT publisher to push state (1/0) changes. In my case I'm using Home Assistant. I can see messages correctly being published, but GPIO state is not being correctly changed.

Here's an example device = "switch" config section

hallonlarm.switch.txt

I'm only using a standard MQTT listening switch. When i publish state messages from my a third publisher like a config tool on my desktop, the switch behaves correctly. So all is working there. Also, i can see with a 'gpio readall' that state change isn't happening on the RPi when remotely published. but when interacting with the RPi Pins directly, a MQTT message is published as expected. (Hallonlarm is correctly reading pin state and publishing changes to MQTT) help! -Cory

bonan commented 6 years ago

You probably want something like this in your config for gpioOut:

/* Tree Lights OUT */
device "tub/light/relay/0" {
    name = "Tree Lights OUT"
    device = "switch"
    feature = {
        info = {
            getTopic = "tub/light/relay/0/state"
            setTopic = "tub/light/relay/0/set"
        }
        on = {
            gpioOut = {
                pin = 22
                invert = false
            }
        }
    }
}

You should then be able to send 1 or 0 to topic tub/light/relay/0/set in order to turn gpio 22 on/off

Note that the device name topic, getTopic and setTopic must be unique (if get and set are the same it would create an infinite loop for instance)

the-butterfry commented 6 years ago

thanks! Assuming get/setTopics don't have to be unique across gpioIn and Out right? I really don't think i'm understanding the in/out functionality correctly.

But alas that still doesn't work. does the getTopic 'state' at the end get automatically substituted out as part of the code? This device only listens to root/topic/set for commands. I don't think 'root/topic/state' is implemented.

EDIT: It's entirely possible i'm totally reading this wrong too. My assumption is that gpioIn is for publishing/setting/state and gpioOut is for subscribing/setting/state. basically gpioPub and gpioSub.. is this correct? or is both pub/sub handled by gpioIn?

the-butterfry commented 6 years ago

dang.. i just can't seem to get it. I think the problem might be something else. It publishes mqtt perfectly, the device responds, as does everything else that is listening to that set topic connected to the broker. The behavior is as though hallonlarm it isn't listening. Is there some sort of logging that can be enabled so I can see if it is actually 'seeing' the published messages?

bonan commented 6 years ago

I don't really get what you're trying to do. Could you explain from the point of view of hallonlarm what should happen?

I.e. something like:

the-butterfry commented 6 years ago

that is exactly what i'm trying to do. both bullet points. Bullet point 1. when an MQTT is received on this topic, hallonlarm should set configured pin to 0/1. This is the part that isn't working Otherwise, it is correctly publishing to tub/light/relay/1/set when it detects a pin state change. as in bullet point 2.

for further color here: the device publishes state changes as a payload of 0/1 to tub/light/relay/0 when a command on /set is published. I have home assistant listening on that and other topics, it correctly receives the message from topic/set and executes a state change. I know things are being published and received correctly.

bonan commented 6 years ago

Your attached config has the same pin (22) for both gpioIn and gpioOut, configuring a pin on a raspberry as both input and output is not possible.

Which is the input pin and which is the output?

You have also stated the same topic for both input and output, this is possible but not recommended (as a state change on the input would trigger the same state for the output)

Which topic should be used for input and which should be used for output?


edit: No, your assumption is not quite correct.

gpioIn is used to read the input state of a GPIO port, i.e. detect if there is a signal or not gpioOut is used to send a signal to a GPIO port

setTopic is the topic hallonlarm subscribes on (only used for gpioOut) and getTopic is the topic hallonlarm publishes to