ESP8266 + Mysensor gateway + Sensors

since @ReneTode pointed out I coud use a ESP8266 mysensor as gateway and sensor at the same time I gave it trying with one of nodemcu and mic module and a button to build the Secret Knock switch, I have copied the main code for the gateway from here and added the parts (of what I think it was necessary) for the Secrect Knock

my sketch: https://raw.githubusercontent.com/Sthopeless/h22s10/master/esp8266_mysensor_secretknock

Flashed and opened the console (wouldnt connect without wiring the nf24 radio) wired everything, button D0 GND and 3V, mic D3, GND and 3V and the radio as they say on the webpage

Added the IP to Hass config: 
mysensors:
  gateways:
    - device: '192.168.1.113'
      tcp_port: 5003
  optimistic: false
  persistence: true
  retain: true
  version: 2.0

Rebooted and got a msg on log saying something like: “child_id 1 already exists in children of node (i think it was 0 at the end not sure now)”

But the secret knock isnt loaded into my hass, any help on what I might be doing wrong?

martin pointed out that if you edit out the lines like:

#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

you shouldnt need the radio

i tried to read the sketch but that quite a lot.
i know that you need to use

send(lockMsg.set(state))

at least once for the sensor to show up. (present isnt enough, unless they fixed that)
i created an extra void for sending data which i call once in the main loop after starting the node.
you could also paste that line at the end of the main loop, upload it, start the node once and after it shows up in HA delete the line again and upload again.

2 Likes

Follow @ReneTode 's advice. Also generally replace delay with wait. Basically never use delay in mysensors sketches. Use wait or sleep to suspend execution. Also make sure you feedback the state change to home assistant from the receive function. Just set the second boolean argument to true when you call setLockState.

2 Likes

Thank you both!
Manage to get it working, already with the Gas Sensor and with the Secret Knock both without any radio.

I see on mysensor webpage they will be at Eindhoven Makers Fair in September 2-3 giving a presentation and I live only few KM away so if you make it there let me know and I will pay you a beer :stuck_out_tongue:

2 Likes

i used to live not that far away, but now its me a bit to far away to drive there and back on one day.
but the thought is what counts :wink:

just talked with my wife about it and she thinks i should go for a weekend.
so it is in my calender to be there 2 days.

1 Like

Great!! I’ll definitely be there on the first day and if it’s worth I’ll go the 2nd day aswell.

i did send you a pm